Bug 1436792 - [py-compat] Improve error messaging when python is missing, r?jmaher draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 08 Feb 2018 14:26:15 -0500
changeset 752683 2ed522e1d99148a5a041b5c9893d1a3452d45ae7
parent 752511 0ac953fcddf10132eaecdb753d72b2ba5a43c32a
child 752684 0e5c2ed9a158be3fa75ac3d96aea8511c1791c0d
push id98346
push userahalberstadt@mozilla.com
push dateThu, 08 Feb 2018 19:56:40 +0000
reviewersjmaher
bugs1436792
milestone60.0a1
Bug 1436792 - [py-compat] Improve error messaging when python is missing, r?jmaher This patch makes a few changes around error handling: 1) Prints the name of the linter that produced non-json output 2) Changes the 'python not found' error to a warning (as this is not fatal) 3) Makes sure said warning only gets printed once (by moving it to the setup function) MozReview-Commit-ID: Dkq7CulTs91
tools/lint/py2.yml
tools/lint/py3.yml
tools/lint/python/compat.py
--- a/tools/lint/py2.yml
+++ b/tools/lint/py2.yml
@@ -58,8 +58,9 @@ py2:
         - tools/power/mach_commands.py
         - tools/profiler
         - tools/rb
         - tools/update-packaging
         - xpcom
     extensions: ['py']
     type: external
     payload: python.compat:lintpy2
+    setup: python.compat:setuppy2
--- a/tools/lint/py3.yml
+++ b/tools/lint/py3.yml
@@ -43,8 +43,9 @@ py3:
         - tools/profiler
         - tools/rb
         - tools/update-packaging
         - xpcom/idl-parser
         - xpcom/typelib
     extensions: ['py']
     type: external
     payload: python.compat:lintpy3
+    setup: python.compat:setuppy3
--- a/tools/lint/python/compat.py
+++ b/tools/lint/python/compat.py
@@ -25,28 +25,38 @@ class PyCompatProcess(ProcessHandlerMixi
         self.config = config
         kwargs['processOutputLine'] = [self.process_line]
         ProcessHandlerMixin.__init__(self, *args, **kwargs)
 
     def process_line(self, line):
         try:
             res = json.loads(line)
         except ValueError:
-            print('Non JSON output from linter, will not be processed: {}'.format(line))
+            print('Non JSON output from {} linter: {}'.format(self.config['name'], line))
             return
 
         res['level'] = 'error'
         results.append(result.from_config(self.config, **res))
 
 
+def setup(python):
+    """Setup doesn't currently do any bootstrapping. For now, this function
+    is only used to print the warning message.
+    """
+    binary = find_executable(python)
+    if not binary:
+        # TODO Bootstrap python2/python3 if not available
+        print('warning: {} not detected, skipping py-compat check'.format(python))
+
+
 def run_linter(python, paths, config, **lintargs):
     binary = find_executable(python)
     if not binary:
-        # TODO bootstrap python3 if not available
-        print('error: {} not detected, aborting py-compat check'.format(python))
+        # If we're in automation, this is fatal. Otherwise, the warning in the
+        # setup method was already printed.
         if 'MOZ_AUTOMATION' in os.environ:
             return 1
         return []
 
     root = lintargs['root']
     pattern = "**/*.py"
     exclude = [mozpath.join(root, e) for e in lintargs.get('exclude', [])]
     files = []
@@ -72,14 +82,22 @@ def run_linter(python, paths, config, **
         try:
             proc.wait()
         except KeyboardInterrupt:
             proc.kill()
 
     return results
 
 
+def setuppy2(root):
+    return setup('python2')
+
+
 def lintpy2(*args, **kwargs):
     return run_linter('python2', *args, **kwargs)
 
 
+def setuppy3(root):
+    return setup('python3')
+
+
 def lintpy3(*args, **kwargs):
     return run_linter('python3', *args, **kwargs)