From 4c232ca3116be5a64eb36b402fd896a346acfcbd Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Thu, 8 Feb 2018 14:26:15 -0500 Subject: [PATCH] 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 --HG-- extra : rebase_source : 5d4bd32a62264a88520c09420f5acd90edcdc740 --- tools/lint/py2.yml | 1 + tools/lint/py3.yml | 1 + tools/lint/python/compat.py | 24 +++++++++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/lint/py2.yml b/tools/lint/py2.yml index f553529aab7a..c6e5164df420 100644 --- a/tools/lint/py2.yml +++ b/tools/lint/py2.yml @@ -61,3 +61,4 @@ py2: extensions: ['py'] type: external payload: python.compat:lintpy2 + setup: python.compat:setuppy2 diff --git a/tools/lint/py3.yml b/tools/lint/py3.yml index 36125eed21e7..7e1f72e0bd0d 100644 --- a/tools/lint/py3.yml +++ b/tools/lint/py3.yml @@ -47,3 +47,4 @@ py3: extensions: ['py'] type: external payload: python.compat:lintpy3 + setup: python.compat:setuppy3 diff --git a/tools/lint/python/compat.py b/tools/lint/python/compat.py index 43fdfb9da860..6f84f8484782 100644 --- a/tools/lint/python/compat.py +++ b/tools/lint/python/compat.py @@ -30,18 +30,28 @@ class PyCompatProcess(ProcessHandlerMixin): 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 [] @@ -77,9 +87,17 @@ def run_linter(python, paths, config, **lintargs): 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)