зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
927e70c7a5
Коммит
4c232ca311
|
@ -61,3 +61,4 @@ py2:
|
||||||
extensions: ['py']
|
extensions: ['py']
|
||||||
type: external
|
type: external
|
||||||
payload: python.compat:lintpy2
|
payload: python.compat:lintpy2
|
||||||
|
setup: python.compat:setuppy2
|
||||||
|
|
|
@ -47,3 +47,4 @@ py3:
|
||||||
extensions: ['py']
|
extensions: ['py']
|
||||||
type: external
|
type: external
|
||||||
payload: python.compat:lintpy3
|
payload: python.compat:lintpy3
|
||||||
|
setup: python.compat:setuppy3
|
||||||
|
|
|
@ -30,18 +30,28 @@ class PyCompatProcess(ProcessHandlerMixin):
|
||||||
try:
|
try:
|
||||||
res = json.loads(line)
|
res = json.loads(line)
|
||||||
except ValueError:
|
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
|
return
|
||||||
|
|
||||||
res['level'] = 'error'
|
res['level'] = 'error'
|
||||||
results.append(result.from_config(self.config, **res))
|
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):
|
def run_linter(python, paths, config, **lintargs):
|
||||||
binary = find_executable(python)
|
binary = find_executable(python)
|
||||||
if not binary:
|
if not binary:
|
||||||
# TODO bootstrap python3 if not available
|
# If we're in automation, this is fatal. Otherwise, the warning in the
|
||||||
print('error: {} not detected, aborting py-compat check'.format(python))
|
# setup method was already printed.
|
||||||
if 'MOZ_AUTOMATION' in os.environ:
|
if 'MOZ_AUTOMATION' in os.environ:
|
||||||
return 1
|
return 1
|
||||||
return []
|
return []
|
||||||
|
@ -77,9 +87,17 @@ def run_linter(python, paths, config, **lintargs):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def setuppy2(root):
|
||||||
|
return setup('python2')
|
||||||
|
|
||||||
|
|
||||||
def lintpy2(*args, **kwargs):
|
def lintpy2(*args, **kwargs):
|
||||||
return run_linter('python2', *args, **kwargs)
|
return run_linter('python2', *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def setuppy3(root):
|
||||||
|
return setup('python3')
|
||||||
|
|
||||||
|
|
||||||
def lintpy3(*args, **kwargs):
|
def lintpy3(*args, **kwargs):
|
||||||
return run_linter('python3', *args, **kwargs)
|
return run_linter('python3', *args, **kwargs)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче