Skip to content

Commit 3745d79

Browse files
committed
Optimize the file exclusion feature
1 parent 1c131d5 commit 3745d79

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Changelog
1313

1414
* Give priority to ``--select`` over ``--ignore``. (Issue #188)
1515

16+
* Compare full path when exluding a file. (Issue #186)
17+
1618

1719
1.4.5 (2013-03-06)
1820
------------------

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The :class:`Checker` class can be used to check a single file.
2727
.. automethod:: check_files(paths=None)
2828
.. automethod:: input_file(filename, lines=None, expected=None, line_offset=0)
2929
.. automethod:: input_dir(dirname)
30-
.. automethod:: excluded(filename)
30+
.. automethod:: excluded(filename, parent=None)
3131
.. automethod:: ignore_code(code)
3232
.. automethod:: get_checks(argument_name)
3333

pep8.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,23 +1632,26 @@ def input_dir(self, dirname):
16321632
print('directory ' + root)
16331633
counters['directories'] += 1
16341634
for subdir in sorted(dirs):
1635-
if self.excluded(os.path.join(root, subdir)):
1635+
if self.excluded(subdir, root):
16361636
dirs.remove(subdir)
16371637
for filename in sorted(files):
16381638
# contain a pattern that matches?
16391639
if ((filename_match(filename, filepatterns) and
1640-
not self.excluded(os.path.join(root, filename)))):
1640+
not self.excluded(filename, root))):
16411641
runner(os.path.join(root, filename))
16421642

1643-
def excluded(self, filename):
1643+
def excluded(self, filename, parent=None):
16441644
"""
16451645
Check if options.exclude contains a pattern that matches filename.
16461646
"""
1647+
if not self.options.exclude:
1648+
return False
16471649
basename = os.path.basename(filename)
1648-
return any((filename_match(filename, self.options.exclude,
1649-
default=False),
1650-
filename_match(basename, self.options.exclude,
1651-
default=False)))
1650+
if filename_match(basename, self.options.exclude):
1651+
return True
1652+
if parent:
1653+
filename = os.path.join(parent, filename)
1654+
return filename_match(filename, self.options.exclude)
16521655

16531656
def ignore_code(self, code):
16541657
"""

0 commit comments

Comments
 (0)