diff --git a/.gitignore b/.gitignore index 3208b8e..9fc083e 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ docs/_build # IDEs /.idea +.venv diff --git a/HISTORY.rst b/HISTORY.rst index 62064a8..84b7a8f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,12 @@ History ------- +0.5.2 (2017-05-18) +~~~~~~~~~~~~~~~~~~ + +* Skipping directories which makes skipping subfolders much faster +* Fixed bug which incorrectly skipped files + 0.5.1 (2017-05-09) ~~~~~~~~~~~~~~~~~~ diff --git a/MANIFEST.in b/MANIFEST.in index 5d11fe6..74d4daa 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include *.rst *.txt -recursive-include tests * +recursive-exclude tests * recursive-exclude * __pycache__ recursive-exclude * *.py[co] diff --git a/importanize/__init__.py b/importanize/__init__.py index 273edef..6162a29 100755 --- a/importanize/__init__.py +++ b/importanize/__init__.py @@ -4,7 +4,7 @@ __author__ = 'Miroslav Shubernetskiy' __email__ = 'miroslav@miki725.com' -__version__ = '0.5.1' +__version__ = '0.5.2' __description__ = ( 'Utility for organizing Python imports using PEP8 or custom rules' ) diff --git a/importanize/__main__.py b/importanize/__main__.py index d5fe87d..649d3b2 100644 --- a/importanize/__main__.py +++ b/importanize/__main__.py @@ -244,7 +244,8 @@ def run(source, config, args, path=None): elif source.is_file(): if config.get('exclude'): - if any(map(lambda i: fnmatch(six.text_type(source.resolve()), i), + norm = os.path.normpath(os.path.abspath(six.text_type(source))) + if any(map(lambda i: fnmatch(norm, i), config.get('exclude'))): log.info('Skipping {}'.format(source)) return @@ -253,6 +254,13 @@ def run(source, config, args, path=None): return run(text, config, args, source) elif source.is_dir(): + if config.get('exclude'): + norm = os.path.normpath(os.path.abspath(six.text_type(source))) + if any(map(lambda i: fnmatch(norm, i), + config.get('exclude'))): + log.info('Skipping {}'.format(source)) + return + files = ( f for f in source.iterdir() if not f.is_file() or f.is_file() and f.suffixes == ['.py'] diff --git a/tests/test_main.py b/tests/test_main.py index 680f7c2..bdacdbd 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -200,7 +200,24 @@ def test_run_dir(self, mock_print): ]) @mock.patch(TESTING_MODULE + '.print', create=True) - def test_run_dir_co(self, mock_print): + def test_run_dir_skipped(self, mock_print): + config = deepcopy(PEP8_CONFIG) + config['exclude'] = ['*/test_data'] + + actual = run( + self.test_data, + config, + mock.Mock(formatter='grouped', + ci=False, + print=True, + header=False), + ) + + self.assertIsNone(actual) + mock_print.assert_not_called() + + @mock.patch(TESTING_MODULE + '.print', create=True) + def test_run_dir_ci(self, mock_print): with self.assertRaises(CIFailure): run( self.test_data,