Skip to content

Commit

Permalink
Don't apply excludes greedily to subdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Mar 16, 2017
1 parent 733a4f0 commit 0559e0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/flake8/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def filenames_from(arg, predicate=None):
# remove it from the list of sub-directories.
for directory in sub_directories:
joined = os.path.join(root, directory)
if predicate(directory) or predicate(joined):
if predicate(joined):
sub_directories.remove(directory)

for filename in files:
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ def test_filenames_from_a_single_file():
assert ['flake8/__init__.py'] == filenames


def test_filenames_from_exclude_doesnt_exclude_directory_names(tmpdir):
"""Verify that we don't greedily exclude subdirs."""
tmpdir.join('1').ensure_dir().join('dont_return_me.py').ensure()
tmpdir.join('2').join('1').ensure_dir().join('return_me.py').ensure()
exclude = [tmpdir.join('1').strpath]

# This acts similar to src.flake8.checker.is_path_excluded
def predicate(pth):
return utils.fnmatch(os.path.abspath(pth), exclude)

with tmpdir.as_cwd():
filenames = list(utils.filenames_from('.', predicate))
assert filenames == [os.path.join('.', '2', '1', 'return_me.py')]


def test_parameters_for_class_plugin():
"""Verify that we can retrieve the parameters for a class plugin."""
class FakeCheck(object):
Expand Down

0 comments on commit 0559e0b

Please sign in to comment.