Skip to content

Commit

Permalink
Merge pull request #39 from miki725/skip
Browse files Browse the repository at this point in the history
Skip
  • Loading branch information
miki725 authored May 18, 2017
2 parents 08db22e + bd7eac5 commit 79f9f32
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ docs/_build

# IDEs
/.idea
.venv
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include *.rst *.txt
recursive-include tests *
recursive-exclude tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]

Expand Down
2 changes: 1 addition & 1 deletion importanize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
10 changes: 9 additions & 1 deletion importanize/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand Down
19 changes: 18 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 79f9f32

Please sign in to comment.