Bug 1398765 - Fix directory exclusion bug in py-compat linters, r?gps draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Mon, 11 Sep 2017 09:03:53 -0400
changeset 662398 f25418d27f633a2dc222e98b871a5185e05fdf35
parent 662290 f9a5e9ed62103c84e4cde915f4d08f1ce71be83e
child 730857 7ee2ff774ae0535b1ca2bbb8fe09652dd597e937
push id79072
push userahalberstadt@mozilla.com
push dateMon, 11 Sep 2017 17:08:00 +0000
reviewersgps
bugs1398765
milestone57.0a1
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
tools/lint/python/compat.py
--- 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]