From c80ea051356ccbcc153292c835916be1e52ffd89 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 16 Jul 2015 22:50:43 -0400 Subject: [PATCH 1/6] fix for #29 since on Windows Python is with uppercase vs python on unix also removed future dependency since six>=1.9 added python_2_unicode_compatible decorator --- importanize/groups.py | 6 +++--- importanize/statements.py | 6 +++--- importanize/utils.py | 3 ++- requirements.txt | 3 +-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/importanize/groups.py b/importanize/groups.py index 7ebc982..317cbcb 100644 --- a/importanize/groups.py +++ b/importanize/groups.py @@ -5,13 +5,13 @@ from collections import OrderedDict, defaultdict from functools import reduce -from future.utils import python_2_unicode_compatible +import six from .formatters import DEFAULT_FORMATTER from .utils import is_std_lib -@python_2_unicode_compatible +@six.python_2_unicode_compatible class BaseImportGroup(object): def __init__(self, config=None, **kwargs): self.config = config or {} @@ -125,7 +125,7 @@ def should_add_statement(self, statement): )) -@python_2_unicode_compatible +@six.python_2_unicode_compatible class ImportGroups(object): def __init__(self, **kwargs): self.groups = [] diff --git a/importanize/statements.py b/importanize/statements.py index d54adc8..8691517 100755 --- a/importanize/statements.py +++ b/importanize/statements.py @@ -3,7 +3,7 @@ import operator import re -from future.utils import python_2_unicode_compatible +import six from .formatters import DEFAULT_FORMATTER from .mixin import ComparatorMixin @@ -13,7 +13,7 @@ DOTS = re.compile(r'^(\.+)(.*)') -@python_2_unicode_compatible +@six.python_2_unicode_compatible class ImportLeaf(ComparatorMixin): """ Data-structure about each import statement leaf-module. @@ -82,7 +82,7 @@ def _type(obj): return self.name > other.name -@python_2_unicode_compatible +@six.python_2_unicode_compatible class ImportStatement(ComparatorMixin): """ Data-structure to store information about diff --git a/importanize/utils.py b/importanize/utils.py index d81f20e..62978fd 100644 --- a/importanize/utils.py +++ b/importanize/utils.py @@ -19,7 +19,8 @@ def ignore_site_packages_paths(): sys.path = list(set(filter( None, filter(lambda i: all(('site-packages' not in i, - 'python' in i or 'pypy' in i)), sys.path) + 'python' in i or 'pypy' in i)), + map(operator.methodcaller('lower'), sys.path)) ))) yield sys.path = paths diff --git a/requirements.txt b/requirements.txt index dd68eb2..e323a45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -future -six +six>=1.9 From 2b09fa82daf5646b10b5e31b2955bf7f69cf5049 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 16 Jul 2015 23:32:34 -0400 Subject: [PATCH 2/6] fixed importanize tests to be executable on Windows --- Makefile | 2 +- importanize/__init__.py | 3 +++ importanize/main.py | 16 +++++++++++----- setup.py | 4 ++-- tests/test_main.py | 18 ++++++++++-------- tests/test_utils.py | 1 - 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index db3d1bc..ed4a366 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ test-coverage: test-all: tox -check: clean-build clean-pyc clean-test lint test-coverage +check: lint clean-build clean-pyc clean-test test-coverage release: clean python setup.py sdist upload diff --git a/importanize/__init__.py b/importanize/__init__.py index 1b413ed..b25154f 100755 --- a/importanize/__init__.py +++ b/importanize/__init__.py @@ -5,3 +5,6 @@ __author__ = 'Miroslav Shubernetskiy' __email__ = 'miroslav@miki725.com' __version__ = '0.4' +__description__ = ( + 'Utility for organizing Python imports using PEP8 or custom rules' +) diff --git a/importanize/main.py b/importanize/main.py index 2a6d370..f22baea 100644 --- a/importanize/main.py +++ b/importanize/main.py @@ -11,7 +11,7 @@ import six -from . import __version__, formatters +from . import __description__, __version__, formatters from .formatters import DEFAULT_FORMATTER from .groups import ImportGroups from .parser import ( @@ -79,8 +79,7 @@ def find_config(): default_config, found_default = find_config() parser = argparse.ArgumentParser( - description='Utility for organizing Python imports ' - 'using PEP8 or custom rules', + description=__description__, ) parser.add_argument( 'path', @@ -231,8 +230,15 @@ def main(): log.debug('Running importanize with {}'.format(args)) if args.version: - msg = 'importanize version: {}' - print(msg.format(__version__)) + msg = ( + 'importanize\n' + '===========\n' + '{}\n\n' + 'version: {}\n' + 'python: {}\n' + 'source: https://github.com/miki725/importanize' + ) + print(msg.format(__description__, __version__, sys.executable)) sys.exit(0) if args.config is None: diff --git a/setup.py b/setup.py index 4de6350..49153ed 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import find_packages, setup -from importanize import __author__, __version__ +from importanize import __author__, __description__, __version__ def read(fname): @@ -31,7 +31,7 @@ def read(fname): name='importanize', version=__version__, author=__author__, - description='Utility for organizing Python imports using PEP8 or custom rules', + description=__description__, long_description='\n\n'.join([readme, history, authors, licence]), url='https://github.com/miki725/importanize', license='MIT', diff --git a/tests/test_main.py b/tests/test_main.py index 07092f5..8e27a77 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -206,7 +206,7 @@ def test_run_folder(self, conf, ) mock_run_importanize.assert_called_once_with( - 'root/foo.py', + os.path.join('root', 'foo.py'), mock.sentinel.config, conf, ) @@ -238,7 +238,7 @@ def test_run_folder_exception(self, conf, ) mock_run_importanize.assert_called_once_with( - 'root/foo.py', + os.path.join('root', 'foo.py'), mock.sentinel.config, conf, ) @@ -247,12 +247,12 @@ def test_run_folder_exception(self, @mock.patch('os.path.exists') @mock.patch('os.getcwd') def test_find_config(self, mock_getcwd, mock_exists): - mock_getcwd.return_value = '/path/to/importanize' + mock_getcwd.return_value = os.path.join('path', 'to', 'importanize') mock_exists.side_effect = False, True config, found = find_config() - self.assertEqual(config, '/path/to/.importanizerc') + self.assertEqual(config, os.path.join('path', 'to', '.importanizerc')) self.assertTrue(bool(found)) @mock.patch(TESTING_MODULE + '.run') @@ -265,7 +265,7 @@ def test_main_without_config(self, args = mock.MagicMock( verbose=1, version=False, - path=['/path/../'], + path=[os.path.join('path', '..')], config=None, ) mock_parse_args.return_value = args @@ -275,7 +275,7 @@ def test_main_without_config(self, mock_parse_args.assert_called_once_with() mock_get_logger.assert_called_once_with('') mock_get_logger().setLevel.assert_called_once_with(logging.INFO) - mock_run.assert_called_once_with('/', PEP8_CONFIG, args) + mock_run.assert_called_once_with(os.getcwd(), PEP8_CONFIG, args) @mock.patch(TESTING_MODULE + '.read') @mock.patch(TESTING_MODULE + '.run') @@ -291,7 +291,7 @@ def test_main_with_config(self, args = mock.MagicMock( verbose=1, version=False, - path=['/path/../'], + path=[os.path.join('path', '..')], config=mock.sentinel.config, ) mock_parse_args.return_value = args @@ -303,7 +303,9 @@ def test_main_with_config(self, mock_get_logger().setLevel.assert_called_once_with(logging.INFO) mock_read.assert_called_once_with(mock.sentinel.config) mock_loads.assert_called_once_with(mock_read.return_value) - mock_run.assert_called_once_with('/', mock_loads.return_value, args) + mock_run.assert_called_once_with( + os.getcwd(), mock_loads.return_value, args + ) @mock.patch(TESTING_MODULE + '.print', create=True) @mock.patch('sys.exit') diff --git a/tests/test_utils.py b/tests/test_utils.py index 9b2685a..3caef12 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -36,7 +36,6 @@ def test_is_std_lib(self): 'collections', 'copy', 'csv', - 'curses', 'datetime', 'decimal', 'fileinput', From 500b9033bc1acb01a24df65fc201919239be3d66 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 16 Jul 2015 23:33:34 -0400 Subject: [PATCH 3/6] added history changes for 0.4.1 release (pending release date) [skip ci] --- HISTORY.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index ab9c83b..7d91617 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,14 @@ History ------- +0.4.1 (2015-07-xx) +~~~~~~~~~~~~~~~~~~ + +* Fixed a bug where ``importanize`` did not correctly detect stdlibs on Windows + (see `#29 `_) +* Removed ``future`` dependency since ``six>=1.9`` includes all the used features +* Fixed tests to be executable on Windows + 0.4 (2015-04-13) ~~~~~~~~~~~~~~~~ From 5c328432cb51d3d9c37339f696418ef928c31469 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 16 Jul 2015 23:35:50 -0400 Subject: [PATCH 4/6] updated travis config to use containers --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 835132d..bf3b0ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,3 +16,5 @@ script: after_success: coveralls + +sudo: false From 3da225c9ac001c690d4d3fcf2af69abaa75ae22f Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Tue, 28 Jul 2015 09:50:08 -0400 Subject: [PATCH 5/6] bumped version to 0.4.1 [ci skip] --- HISTORY.rst | 2 +- importanize/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 7d91617..bf3644a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,7 +3,7 @@ History ------- -0.4.1 (2015-07-xx) +0.4.1 (2015-07-28) ~~~~~~~~~~~~~~~~~~ * Fixed a bug where ``importanize`` did not correctly detect stdlibs on Windows diff --git a/importanize/__init__.py b/importanize/__init__.py index b25154f..6110a41 100755 --- a/importanize/__init__.py +++ b/importanize/__init__.py @@ -4,7 +4,7 @@ __author__ = 'Miroslav Shubernetskiy' __email__ = 'miroslav@miki725.com' -__version__ = '0.4' +__version__ = '0.4.1' __description__ = ( 'Utility for organizing Python imports using PEP8 or custom rules' ) From d75ff24900b4cbbdcd9cbccc32dfc96eed643ae9 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Tue, 28 Jul 2015 09:59:15 -0400 Subject: [PATCH 6/6] fixed json config examples in README --- README.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 6938302..f45b8d3 100644 --- a/README.rst +++ b/README.rst @@ -63,13 +63,13 @@ Config file is simply a ``json`` file like this:: "path/to/file", "path/to/files/ignore_*.py" ], - "formatter": 'grouped', + "formatter": "grouped", "groups": [ { - "type": "stdlib", + "type": "stdlib" }, { - "type": "remainder", + "type": "remainder" }, { "type": "packages", @@ -78,24 +78,24 @@ Config file is simply a ``json`` file like this:: ] }, { - "type": "local", + "type": "local" } - ], + ] } Default config looks something like:: { "groups": [ { - "type": "stdlib", + "type": "stdlib" }, { - "type": "remainder", + "type": "remainder" }, { - "type": "local", + "type": "local" } - ], + ] } Currently the only required key is ``"groups"`` which must be an array