From 9f1d512f716fe9fd2d318628044368927ca8a2be Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Mon, 24 Feb 2014 08:26:56 -0800 Subject: Add tox.ini for tox --- tox.ini | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..dac85a39 --- /dev/null +++ b/tox.ini @@ -0,0 +1,12 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py26, py27, py32, py33, pypy + +[testenv] +commands = py.test {posargs} +deps = + pytest -- cgit v1.2.1 From 9d8555fba7dc7d7a86bd82921ecfceb8f4720465 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Mon, 24 Feb 2014 09:09:18 -0800 Subject: .travis.yml: Add pypy --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1e66aee5..12bbf4c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: python python: + - "pypy" - "2.6" - "2.7" - "3.2" - "3.3" -script: python setup.py test \ No newline at end of file +script: python setup.py test -- cgit v1.2.1 From 2d19330ecde75466db6fe4edf1f1250076d8cb2f Mon Sep 17 00:00:00 2001 From: wimglenn Date: Fri, 28 Feb 2014 18:32:51 +0000 Subject: fix docstring bug The module docstring specifies the config file is at ~/.isort.conf but the code looks in ~/.isort.cfg, hence I spent a long time trying to figure out why my config file was silently being ignored! --- isort/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isort/settings.py b/isort/settings.py index 0393b149..a94c622c 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -3,7 +3,7 @@ Defines how the default settings for isort should be loaded (First from the default setting dictionary at the top of the file, then overridden by any settings - in ~/.isort.conf if there are any) + in ~/.isort.cfg if there are any) Copyright (C) 2013 Timothy Edmund Crosley -- cgit v1.2.1 From 991b0bcf6d1914873005e44401df34ece388e144 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 6 Mar 2014 23:41:43 -0500 Subject: Add akcnowledgement for the awesome github users who have helped improve isort --- ACKNOWLEDGEMENTS.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ACKNOWLEDGEMENTS.md diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md new file mode 100644 index 00000000..785e5ebb --- /dev/null +++ b/ACKNOWLEDGEMENTS.md @@ -0,0 +1,40 @@ +Original Creator & Maintainer +=================== +- Timothy Edmund Crosley (@timothycrosley) + +Plugin Writers +=================== +- *VIM* - Juan Pedro Fisanotti (@fisadev) +- *Emacs* - Friedrich Paetzke (@paetzke) +- *Sublime* - Thijs de Zoute (@thijsdezoete) + +Notable Bug Reporters +=================== +- Bengt Lüers (@Bengt) +- Chris Adams (@acdha) + +Code Contributors +=================== +- Aaron Gallagher (@habnabit) +- Thomas Grainger (@graingert) +- Thijs de Zoute (@thijsdezoete) +- Marc Abramowitz (@msabramo) +- Daniel Cowgill (@dcowgill) +- Francois Lebel (@flebel) +- Antoni Segura Puimedon (@celebdor) +- Pablo (@oubiga) +- Oskar Hahn (@ostcar) +- @wimglenn +- Matt Caldwell (@mattcaldwell) +- Dwayne Bailey (@dwaynebailey) +- Ionel Cristian Mărieș (@ionelmc) +- Chris Adams (@acdha) +- GuoJing (@GuoJing) + +-------------------------------------------- + +A sincere thanks to everyone who has helped isort be the great utility it is today! +It would not be one-hundredth as useful and consistent as it is now without the help of your bug reports, +commits, and suggestions. You guys rock! + +~Timothy Crosley -- cgit v1.2.1 From a52e0d782c0fab2ebfff5a4a56c4189243298e2c Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 6 Mar 2014 23:52:55 -0500 Subject: Add test for desired behaviour --- test_isort.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test_isort.py b/test_isort.py index f66dca2f..6254d6a0 100644 --- a/test_isort.py +++ b/test_isort.py @@ -825,3 +825,12 @@ def test_keep_comments(): assert SortImports(file_contents=test_input, combine_as_imports=True, line_length=45).output == \ ("from a import (b, # My Comment1; My Comment2 is really really really really long\n" " c, d)\n") + + +def test_multiline_split_on_dot(): + """Test to ensure isort correctly handles multiline imports, even when split right after a '.'""" + test_input = ("from my_lib.my_package.test.level_1.level_2.level_3.level_4.level_5.\\\n" + " my_module import my_function") + assert SortImports(file_contents=test_input, line_length=70) == \ + ("from my_lib.my_package.test.level_1.level_2.level_3.level_4.level_5. \\\n" + " my_module import my_function") -- cgit v1.2.1 From 6cc8e4d7954b684393dc83720a691979f2236cfe Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 6 Mar 2014 23:53:48 -0500 Subject: Fix test case --- test_isort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_isort.py b/test_isort.py index 6254d6a0..f85e8e22 100644 --- a/test_isort.py +++ b/test_isort.py @@ -831,6 +831,6 @@ def test_multiline_split_on_dot(): """Test to ensure isort correctly handles multiline imports, even when split right after a '.'""" test_input = ("from my_lib.my_package.test.level_1.level_2.level_3.level_4.level_5.\\\n" " my_module import my_function") - assert SortImports(file_contents=test_input, line_length=70) == \ + assert SortImports(file_contents=test_input, line_length=70).output == \ ("from my_lib.my_package.test.level_1.level_2.level_3.level_4.level_5. \\\n" " my_module import my_function") -- cgit v1.2.1 From d865d3cdd00995cfa438e6b8a51bac324b1926ec Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 7 Mar 2014 01:25:38 -0500 Subject: Update code to correctly concatenate multi line import strings --- isort/isort.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/isort/isort.py b/isort/isort.py index 9870725e..d37e0fe4 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -496,7 +496,10 @@ class SortImports(object): else: while line.strip().endswith("\\"): line, comments = self._strip_comments(self._get_line(), comments) - import_string += "\n" + line + if import_string.strip().endswith(" import") or line.strip().startswith("import "): + import_string += "\n" + line + else: + import_string += line.strip() if import_type == "from": parts = import_string.split(" import ") -- cgit v1.2.1 From 405f936afa842e3f6ec59f3aa497755ae85491cc Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 7 Mar 2014 01:56:53 -0500 Subject: Fix test, adding new line after multi line imports --- test_isort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_isort.py b/test_isort.py index f85e8e22..4a581b59 100644 --- a/test_isort.py +++ b/test_isort.py @@ -833,4 +833,4 @@ def test_multiline_split_on_dot(): " my_module import my_function") assert SortImports(file_contents=test_input, line_length=70).output == \ ("from my_lib.my_package.test.level_1.level_2.level_3.level_4.level_5. \\\n" - " my_module import my_function") + " my_module import my_function\n") -- cgit v1.2.1 From c335849efe4dc6b28338e97b7aa9fe9ede1d6566 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 7 Mar 2014 01:57:12 -0500 Subject: Fix isort to correctly wrap multi-line import statements --- isort/isort.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/isort/isort.py b/isort/isort.py index d37e0fe4..350b4fb6 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -250,6 +250,20 @@ class SortImports(object): return comments and "{0} # {1}".format(self._strip_comments(original_string)[0], "; ".join(comments)) or original_string + def _wrap(self, line): + """ + Returns an import wrapped to the specified line-length, if possible. + """ + if len(line) > self.config['line_length'] and "." in line: + line_parts = line.split(".") + next_line = [] + while (len(line) + 2) > self.config['line_length'] and line_parts: + next_line.append(line_parts.pop()) + line = ".".join(line_parts) + return "{0}. \\\n{1}".format(line, self._wrap(self.config['indent'] + ".".join(next_line))) + + return line + def _add_formatted_imports(self): """Adds the imports back to the file. @@ -299,14 +313,15 @@ class SortImports(object): if from_imports: comments = self.comments['from'].get(module) if "*" in from_imports: - import_statement = self._add_comments(comments, "{0}*".format(import_start)) + import_statement = self._wrap(self._add_comments(comments, "{0}*".format(import_start))) elif self.config['force_single_line']: - import_statement = self._add_comments(comments, import_start + from_imports.pop(0)) + import_statement = self._wrap(self._add_comments(comments, import_start + from_imports.pop(0))) for from_import in from_imports: import_statement += "\n{0}{1}".format(import_start, from_import) comments = None else: - import_statement = self._add_comments(comments, import_start + (", ").join(from_imports)) + import_statement = self._wrap(self._add_comments(comments, + import_start + (", ").join(from_imports))) if len(import_statement) > self.config['line_length'] and len(from_imports) > 1: output_mode = settings.WrapModes._fields[self.config.get('multi_line_output', 0)].lower() formatter = getattr(self, "_output_" + output_mode, self._output_grid) @@ -499,7 +514,8 @@ class SortImports(object): if import_string.strip().endswith(" import") or line.strip().startswith("import "): import_string += "\n" + line else: - import_string += line.strip() + import_string = import_string.rstrip().rstrip("\\") + line.lstrip() + print(import_string) if import_type == "from": parts = import_string.split(" import ") -- cgit v1.2.1 From 2219a323571c4bdd3caafbff9a5fd7a256b7360a Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 7 Mar 2014 02:00:11 -0500 Subject: Only wrap single line statements for simplities sake --- isort/isort.py | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/isort/isort.py b/isort/isort.py index 350b4fb6..ddc82fe7 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -320,27 +320,31 @@ class SortImports(object): import_statement += "\n{0}{1}".format(import_start, from_import) comments = None else: - import_statement = self._wrap(self._add_comments(comments, - import_start + (", ").join(from_imports))) - if len(import_statement) > self.config['line_length'] and len(from_imports) > 1: - output_mode = settings.WrapModes._fields[self.config.get('multi_line_output', 0)].lower() - 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'] - import_statement = formatter(import_start, copy.copy(from_imports), - dynamic_indent, indent, line_length, comments) - if self.config['balanced_wrapping']: - lines = import_statement.split("\n") - line_count = len(lines) - minimum_length = min([len(line) for line in lines[:-1]]) - new_import_statement = import_statement - while len(lines[-1]) < minimum_length and len(lines) == line_count and line_length > 10: - import_statement = new_import_statement - line_length -= 1 - new_import_statement = formatter(import_start, copy.copy(from_imports), - dynamic_indent, indent, line_length, comments) - lines = new_import_statement.split("\n") + import_statement = self._add_comments(comments, import_start + (", ").join(from_imports)) + if len(import_statement) > self.config['line_length']: + if len(from_imports) > 1: + output_mode = settings.WrapModes._fields[self.config.get('multi_line_output', + 0)].lower() + 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'] + import_statement = formatter(import_start, copy.copy(from_imports), + dynamic_indent, indent, line_length, comments) + if self.config['balanced_wrapping']: + lines = import_statement.split("\n") + line_count = len(lines) + minimum_length = min([len(line) for line in lines[:-1]]) + new_import_statement = import_statement + while (len(lines[-1]) < minimum_length and + len(lines) == line_count and line_length > 10): + import_statement = new_import_statement + line_length -= 1 + new_import_statement = formatter(import_start, copy.copy(from_imports), + dynamic_indent, indent, line_length, comments) + lines = new_import_statement.split("\n") + else: + import_statement = self._wrap(import_statement) section_output.append(import_statement) -- cgit v1.2.1 From 682a3c1e921f92155a24e54c139222119bbeb1ce Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 7 Mar 2014 02:01:09 -0500 Subject: Remove undesired print statement --- isort/isort.py | 1 - 1 file changed, 1 deletion(-) diff --git a/isort/isort.py b/isort/isort.py index ddc82fe7..4ba0ff5a 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -519,7 +519,6 @@ class SortImports(object): import_string += "\n" + line else: import_string = import_string.rstrip().rstrip("\\") + line.lstrip() - print(import_string) if import_type == "from": parts = import_string.split(" import ") -- cgit v1.2.1 From 5aa7e1465b928a1317359316511431c4efecb025 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 7 Mar 2014 02:09:43 -0500 Subject: Bump release to 3.6.2 --- isort/__init__.py | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/isort/__init__.py b/isort/__init__.py index 0c8be9b5..541b2034 100644 --- a/isort/__init__.py +++ b/isort/__init__.py @@ -25,4 +25,4 @@ from __future__ import absolute_import, division, print_function, unicode_litera from . import settings from .isort import SECTION_NAMES, SECTIONS, SortImports -__version__ = "3.6.1" +__version__ = "3.6.2" diff --git a/setup.py b/setup.py index 94ccea71..1273ced8 100755 --- a/setup.py +++ b/setup.py @@ -42,13 +42,13 @@ except (IOError, ImportError, OSError, RuntimeError): readme = '' setup(name='isort', - version='3.6.1', + version='3.6.2', description='A Python utility / library to sort Python imports.', long_description=readme, author='Timothy Crosley', author_email='timothy.crosley@gmail.com', url='https://github.com/timothycrosley/isort', - download_url='https://github.com/timothycrosley/isort/archive/3.6.1.tar.gz', + download_url='https://github.com/timothycrosley/isort/archive/3.6.2.tar.gz', license="MIT", entry_points={ 'console_scripts': [ -- cgit v1.2.1