summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-01-05 15:22:01 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2020-01-05 15:22:01 -0800
commit07413b3ee7e9f1730c148d25d53125df48adbc31 (patch)
tree642872d0ff87d23ad0fb4992fdd6b71b6ae4f083
parent39ed7a6032e39022dd2cdf1e9e0810b9757600b8 (diff)
downloadisort-07413b3ee7e9f1730c148d25d53125df48adbc31.tar.gz
Fix issue #1061
-rw-r--r--isort/main.py12
-rw-r--r--isort/settings.py5
-rw-r--r--tests/test_isort.py12
3 files changed, 21 insertions, 8 deletions
diff --git a/isort/main.py b/isort/main.py
index 18c4d164..dfd09873 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -296,13 +296,6 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
action="store_true",
help="Turns off default behavior that removes direct imports when as imports exist.",
)
- parser.add_argument(
- "-l",
- "--lines",
- help="[Deprecated] The max length of an import line (used for wrapping " "long imports).",
- dest="line_length",
- type=int,
- )
parser.add_argument("-lai", "--lines-after-imports", dest="lines_after_imports", type=int)
parser.add_argument("-lbt", "--lines-between-types", dest="lines_between_types", type=int)
parser.add_argument(
@@ -481,7 +474,9 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
help="Returns just the current version number without the logo",
)
parser.add_argument(
+ "-l",
"-w",
+ "--line-length",
"--line-width",
help="The max length of an import line (used for wrapping long imports).",
dest="line_length",
@@ -492,7 +487,8 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
"--wrap-length",
dest="wrap_length",
type=int,
- help="Specifies how long lines that are wrapped should be, if not set line_length is used.",
+ help="Specifies how long lines that are wrapped should be, if not set line_length is used."
+ "\nNOTE: wrap_length must be LOWER than or equal to line_length.",
)
parser.add_argument(
"--ws",
diff --git a/isort/settings.py b/isort/settings.py
index 387d10e4..04b488f1 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -208,6 +208,11 @@ class _Config:
object.__setattr__(self, "no_sections", True)
object.__setattr__(self, "lines_between_types", 1)
object.__setattr__(self, "from_first", True)
+ if self.wrap_length > self.line_length:
+ raise ValueError(
+ "wrap_length must be set lower than or equal to line_length: "
+ f"{self.wrap_length} > {self.line_length}."
+ )
_DEFAULT_SETTINGS = {**vars(_Config()), "source": "defaults"}
diff --git a/tests/test_isort.py b/tests/test_isort.py
index db982587..9e7bcb35 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -196,6 +196,18 @@ def test_line_length() -> None:
" lib22)\n"
)
+ test_input = (
+ "from .test import a_very_long_function_name_that_exceeds_the_normal_pep8_line_length\n"
+ )
+ with pytest.raises(ValueError):
+ test_output = SortImports(
+ file_contents=REALLY_LONG_IMPORT, line_length=80, wrap_length=99
+ ).output
+ test_output = (
+ SortImports(file_contents=REALLY_LONG_IMPORT, line_length=100, wrap_length=99).output
+ == test_input
+ )
+
def test_output_modes() -> None:
"""Test setting isort to use various output modes works as expected"""