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
This commit is contained in:
Andrew Halberstadt 2018-02-08 14:26:15 -05:00
Родитель 927e70c7a5
Коммит 4c232ca311
3 изменённых файлов: 23 добавлений и 3 удалений

Просмотреть файл

@ -61,3 +61,4 @@ py2:
extensions: ['py']
type: external
payload: python.compat:lintpy2
setup: python.compat:setuppy2

Просмотреть файл

@ -47,3 +47,4 @@ py3:
extensions: ['py']
type: external
payload: python.compat:lintpy3
setup: python.compat:setuppy3

Просмотреть файл

@ -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)