Bug 1398765 - Fix directory exclusion bug in py-compat linters, r?gps
The excluded directories aren't being properly handled in the py2/py3 compat
linters. In order for FileFinder to apply the exclusions properly they need
to either be relative to or contained by the base.
This means that currently the following will work:
./mach lint -l py2 <topsrcdir>
./mach lint -l py2 testing/mochitest
But this is broken:
./mach lint -l py2 testing
This change fixes the compat linters so exclude paths will be made relative
to the FileFinder base before passing them in. Any exclude not contained by
the base is simply discarded as it won't be relevant to that FileFinder
instance anyway.
MozReview-Commit-ID: LJx97TvKlSa
--- a/tools/lint/python/compat.py
+++ b/tools/lint/python/compat.py
@@ -4,16 +4,17 @@
from __future__ import absolute_import, print_function
import json
import os
import tempfile
from distutils.spawn import find_executable
+import mozpack.path as mozpath
from mozpack.files import FileFinder
from mozprocess import ProcessHandlerMixin
from mozlint import result
here = os.path.abspath(os.path.dirname(__file__))
results = []
@@ -40,25 +41,29 @@ def run_linter(python, paths, config, **
binary = find_executable(python)
if not binary:
# TODO bootstrap python3 if not available
print('error: {} not detected, aborting py-compat check'.format(python))
if 'MOZ_AUTOMATION' in os.environ:
return 1
return []
+ root = lintargs['root']
pattern = "**/*.py"
- exclude = lintargs.get('exclude', [])
+ exclude = [mozpath.join(root, e) for e in lintargs.get('exclude', [])]
files = []
for path in paths:
+ path = mozpath.normsep(path)
if os.path.isfile(path):
files.append(path)
continue
- finder = FileFinder(path, ignore=exclude)
+ ignore = [e[len(path):].lstrip('/') for e in exclude
+ if mozpath.commonprefix((path, e)) == path]
+ finder = FileFinder(path, ignore=ignore)
files.extend([os.path.join(path, p) for p, f in finder.find(pattern)])
with tempfile.NamedTemporaryFile(mode='w') as fh:
fh.write('\n'.join(files))
fh.flush()
cmd = [binary, os.path.join(here, 'check_compat.py'), fh.name]