summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Edmund Crosley <timothy.crosley@gmail.com>2018-02-01 22:49:06 -0800
committerGitHub <noreply@github.com>2018-02-01 22:49:06 -0800
commit68e5f61c1108e287b291a8272f36ec9969c9e60f (patch)
tree27776e591884561a94746637ea7d71871b7d2812
parent556e40a49746757704e33fec6fecaaef43a892c4 (diff)
parent1db36205f016ae4b72bb713aedf7f96b1be43723 (diff)
downloadisort-68e5f61c1108e287b291a8272f36ec9969c9e60f.tar.gz
Merge pull request #657 from timothycrosley/feature/fix-issue-654
Feature/fix issue 654
-rw-r--r--isort/isort.py14
-rwxr-xr-xisort/main.py2
-rw-r--r--isort/settings.py3
-rw-r--r--test_isort.py20
4 files changed, 28 insertions, 11 deletions
diff --git a/isort/isort.py b/isort/isort.py
index ecb2bf24..0a672db3 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -699,7 +699,8 @@ class SortImports(object):
"," if self.config['include_trailing_comma'] else "",
)
- def _output_vertical_grid_common(self, statement, imports, white_space, indent, line_length, comments, need_trailing_char):
+ def _output_vertical_grid_common(self, statement, imports, white_space, indent, line_length, comments,
+ need_trailing_char):
statement += self._add_comments(comments, "(") + self.line_separator + indent + imports.pop(0)
while imports:
next_import = imports.pop(0)
@@ -717,11 +718,16 @@ class SortImports(object):
return statement
def _output_vertical_grid(self, statement, imports, white_space, indent, line_length, comments):
- return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments, True) + ")"
+ return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments,
+ True) + ")"
def _output_vertical_grid_grouped(self, statement, imports, white_space, indent, line_length, comments):
- return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments, False) \
- + self.line_separator + ")"
+ return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments,
+ True) + self.line_separator + ")"
+
+ def _output_vertical_grid_grouped_no_comma(self, statement, imports, white_space, indent, line_length, comments):
+ return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments,
+ False) + self.line_separator + ")"
def _output_noqa(self, statement, imports, white_space, indent, line_length, comments):
retval = '{0}{1}'.format(statement, ', '.join(imports))
diff --git a/isort/main.py b/isort/main.py
index 8c748b20..efb3793d 100755
--- a/isort/main.py
+++ b/isort/main.py
@@ -230,7 +230,7 @@ def create_parser():
dest='length_sort', action='store_true')
parser.add_argument('-m', '--multi-line', dest='multi_line_output', type=int, choices=[0, 1, 2, 3, 4, 5],
help='Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, '
- '5-vert-grid-grouped).')
+ '5-vert-grid-grouped, 6-vert-grid-grouped-no-comma).')
inline_args_group.add_argument('-nis', '--no-inline-sort', dest='no_inline_sort', action='store_true',
help='Leaves `from` imports with multiple imports \'as-is\' (e.g. `from foo import a, c ,b`).')
parser.add_argument('-nlb', '--no-lines-before', help='Sections which should not be split with previous by empty lines',
diff --git a/isort/settings.py b/isort/settings.py
index 09feb5dc..dd0a7110 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -41,7 +41,8 @@ except ImportError:
MAX_CONFIG_SEARCH_DEPTH = 25 # The number of parent directories isort will look for a config file within
DEFAULT_SECTIONS = ('FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER')
-WrapModes = ('GRID', 'VERTICAL', 'HANGING_INDENT', 'VERTICAL_HANGING_INDENT', 'VERTICAL_GRID', 'VERTICAL_GRID_GROUPED', 'NOQA')
+WrapModes = ('GRID', 'VERTICAL', 'HANGING_INDENT', 'VERTICAL_HANGING_INDENT', 'VERTICAL_GRID', 'VERTICAL_GRID_GROUPED',
+ 'VERTICAL_GRID_GROUPED_NO_COMMA', 'NOQA')
WrapModes = namedtuple('WrapModes', WrapModes)(*range(len(WrapModes)))
# Note that none of these lists must be complete as they are simply fallbacks for when included auto-detection fails.
diff --git a/test_isort.py b/test_isort.py
index db505647..56cf85fe 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -153,6 +153,13 @@ def test_line_length():
" lib18, lib20,\n"
" lib21, lib22)\n")
+ TEST_INPUT = ('from django.contrib.gis.gdal.field import (\n'
+ ' OFTDate, OFTDateTime, OFTInteger, OFTInteger64, OFTReal, OFTString,\n'
+ ' OFTTime,\n'
+ ')\n') # Test case described in issue #654
+ assert SortImports(file_contents=TEST_INPUT, include_trailing_comma=True, line_length=79,
+ multi_line_output=WrapModes.VERTICAL_GRID_GROUPED, balanced_wrapping=False).output == TEST_INPUT
+
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"
@@ -353,11 +360,14 @@ def test_output_modes():
output_noqa = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT,
multi_line_output=WrapModes.NOQA).output
- assert output_noqa == "from third_party import lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22 # NOQA comment\n" # NOQA
-
- test_output_vertical_grid_grouped_doesnt_wrap_early = SortImports(file_contents=SINGLE_LINE_LONG_IMPORT,
- multi_line_output=WrapModes.VERTICAL_GRID_GROUPED,
- line_length=40, indent=' ').output
+ assert output_noqa == ("from third_party import lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11,"
+ " lib12, lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22 "
+ "# NOQA comment\n")
+
+ test_case = SortImports(file_contents=SINGLE_LINE_LONG_IMPORT,
+ multi_line_output=WrapModes.VERTICAL_GRID_GROUPED_NO_COMMA,
+ line_length=40, indent=' ').output
+ test_output_vertical_grid_grouped_doesnt_wrap_early = test_case
assert test_output_vertical_grid_grouped_doesnt_wrap_early == ("from third_party import (\n"
" lib1, lib2, lib3, lib4, lib5, lib5ab\n"
")\n")