summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Edmund Crosley <timothy.crosley@gmail.com>2015-02-05 16:23:37 -0500
committerTimothy Edmund Crosley <timothy.crosley@gmail.com>2015-02-05 16:23:37 -0500
commitd8cea240730dae6f571e41ddad22e61217d40943 (patch)
treed824d86ceaa73549e047d209ac7a81d9aa689f33
parent691afe42cf655f1ce0e8c80d3c8be12500282f19 (diff)
parentdb059715209c7dda570bb20ea4783a3c80b8df0f (diff)
downloadisort-d8cea240730dae6f571e41ddad22e61217d40943.tar.gz
Merge pull request #241 from timothycrosley/feature/fix-issue-225
Feature/fix issue 225
-rw-r--r--isort/isort.py4
-rwxr-xr-xisort/main.py4
-rw-r--r--isort/settings.py1
-rw-r--r--test_isort.py24
4 files changed, 30 insertions, 3 deletions
diff --git a/isort/isort.py b/isort/isort.py
index 114daf07..8b6ae933 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -274,7 +274,7 @@ class SortImports(object):
if splitter in line and not line.strip().startswith(splitter):
line_parts = line.split(splitter)
next_line = []
- while (len(line) + 2) > self.config['line_length'] and line_parts:
+ while (len(line) + 2) > (self.config['wrap_length'] or self.config['line_length']) and line_parts:
next_line.append(line_parts.pop())
line = splitter.join(line_parts)
if not line:
@@ -373,7 +373,7 @@ class SortImports(object):
formatter = getattr(self, "_output_" + output_mode, self._output_grid)
dynamic_indent = " " * (len(import_start) + 1)
indent = self.config['indent']
- line_length = self.config['line_length']
+ line_length = self.config['wrap_length'] or self.config['line_length']
import_statement = formatter(import_start, copy.copy(from_imports),
dynamic_indent, indent, line_length, comments)
if self.config['balanced_wrapping']:
diff --git a/isort/main.py b/isort/main.py
index 1ed1030e..a73ad329 100755
--- a/isort/main.py
+++ b/isort/main.py
@@ -107,7 +107,9 @@ def main():
parser.add_argument('-sp', '--settings-path', dest="settings_path",
help='Explicitly set the settings path instead of auto determining based on file location.')
parser.add_argument('-ff', '--from-first', dest='from_first',
- help="Switches the typical ordering preference, showing from imports first then straight ones")
+ help="Switches the typical ordering preference, showing from imports first then straight ones.")
+ parser.add_argument('-wl', '--wrap-length', dest='wrap_length',
+ help="Specifies how long lines that are wrapped should be, if not set line_length is used.")
arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value)
file_names = arguments.pop('files', [])
diff --git a/isort/settings.py b/isort/settings.py
index cdb5cd74..0b14bec6 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -44,6 +44,7 @@ WrapModes = namedtuple('WrapModes', WrapModes)(*range(len(WrapModes)))
default = {'force_to_top': [],
'skip': ['__init__.py', ],
'line_length': 79,
+ 'wrap_length': 0,
'known_future_library': ['__future__'],
'known_standard_library': ["abc", "anydbm", "argparse", "array", "asynchat", "asyncore", "atexit", "base64",
"BaseHTTPServer", "bisect", "bz2", "calendar", "cgitb", "cmd", "codecs",
diff --git a/test_isort.py b/test_isort.py
index 96896288..a0a0dac5 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -143,6 +143,30 @@ def test_line_length():
" lib21, lib22)\n")
+ test_output = SortImports(file_contents=REALLY_LONG_IMPORT, line_length=42, wrap_length=32).output
+ assert test_output == ("from third_party import (lib1,\n"
+ " lib2,\n"
+ " lib3,\n"
+ " lib4,\n"
+ " lib5,\n"
+ " lib6,\n"
+ " lib7,\n"
+ " lib8,\n"
+ " lib9,\n"
+ " lib10,\n"
+ " lib11,\n"
+ " lib12,\n"
+ " lib13,\n"
+ " lib14,\n"
+ " lib15,\n"
+ " lib16,\n"
+ " lib17,\n"
+ " lib18,\n"
+ " lib20,\n"
+ " lib21,\n"
+ " lib22)\n")
+
+
def test_output_modes():
"""Test setting isort to use various output modes works as expected"""
test_output_grid = SortImports(file_contents=REALLY_LONG_IMPORT,