Bug 1288432 - Use new mozlint configuration for flake8 linter, r=bc

MozReview-Commit-ID: 9vC6lI2j5nS

--HG--
rename : tools/lint/flake8.lint.py => tools/lint/flake8_/__init__.py
rename : tools/lint/flake8/flake8_requirements.txt => tools/lint/flake8_/flake8_requirements.txt
extra : rebase_source : 1cc39782391fa15100bf0765c28f21eb11b115e4
This commit is contained in:
Andrew Halberstadt 2017-06-02 09:46:01 -04:00
Родитель 9a082a086c
Коммит 958af4447e
5 изменённых файлов: 64 добавлений и 65 удалений

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

@ -2,4 +2,3 @@
# See http://pep8.readthedocs.io/en/latest/intro.html#configuration # See http://pep8.readthedocs.io/en/latest/intro.html#configuration
ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402 ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402
max-line-length = 99 max-line-length = 99
filename = *.py, +.lint

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

@ -17,8 +17,8 @@ ADD topsrcdir/taskcluster/docker/recipes/install-node.sh /build/install-node.sh
# %include taskcluster/docker/recipes/install-mercurial.sh # %include taskcluster/docker/recipes/install-mercurial.sh
ADD topsrcdir/taskcluster/docker/recipes/install-mercurial.sh /build/install-mercurial.sh ADD topsrcdir/taskcluster/docker/recipes/install-mercurial.sh /build/install-mercurial.sh
ADD system-setup.sh /tmp/system-setup.sh ADD system-setup.sh /tmp/system-setup.sh
# %include tools/lint/flake8/flake8_requirements.txt # %include tools/lint/flake8_/flake8_requirements.txt
ADD topsrcdir/tools/lint/flake8/flake8_requirements.txt /tmp/flake8_requirements.txt ADD topsrcdir/tools/lint/flake8_/flake8_requirements.txt /tmp/flake8_requirements.txt
# %include tools/lint/tox/tox_requirements.txt # %include tools/lint/tox/tox_requirements.txt
ADD topsrcdir/tools/lint/tox/tox_requirements.txt /tmp/tox_requirements.txt ADD topsrcdir/tools/lint/tox/tox_requirements.txt /tmp/tox_requirements.txt
RUN bash /tmp/system-setup.sh RUN bash /tmp/system-setup.sh

23
tools/lint/flake8.yml Normal file
Просмотреть файл

@ -0,0 +1,23 @@
flake8:
description: Python linter
include:
- layout/tools/reftest
- python/mozlint
- security/manager
- taskcluster
- testing/firefox-ui
- testing/marionette/client
- testing/marionette/harness
- testing/marionette/puppeteer
- testing/mozbase
- testing/mochitest
- testing/talos/
- tools/git
- tools/lint
- tools/mercurial
- toolkit/components/telemetry
exclude:
- testing/mochitest/pywebsocket
extensions: ['.py']
type: external
payload: flake8_:lint

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

@ -1,5 +1,3 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
@ -10,13 +8,13 @@ import signal
import subprocess import subprocess
import which import which
from mozprocess import ProcessHandler from mozprocess import ProcessHandlerMixin
from mozlint import result from mozlint import result
here = os.path.abspath(os.path.dirname(__file__)) here = os.path.abspath(os.path.dirname(__file__))
FLAKE8_REQUIREMENTS_PATH = os.path.join(here, 'flake8', 'flake8_requirements.txt') FLAKE8_REQUIREMENTS_PATH = os.path.join(here, 'flake8_requirements.txt')
FLAKE8_NOT_FOUND = """ FLAKE8_NOT_FOUND = """
Could not find flake8! Install flake8 and try again. Could not find flake8! Install flake8 and try again.
@ -55,42 +53,39 @@ The offset is of the form (lineno_offset, num_lines) and is passed
to the lineoffset property of `ResultContainer`. to the lineoffset property of `ResultContainer`.
""" """
EXTENSIONS = ['.py', '.lint']
results = [] results = []
def process_line(line): class Flake8Process(ProcessHandlerMixin):
# Escape slashes otherwise JSON conversion will not work def __init__(self, config, *args, **kwargs):
line = line.replace('\\', '\\\\') self.config = config
try: kwargs['processOutputLine'] = [self.process_line]
res = json.loads(line) ProcessHandlerMixin.__init__(self, *args, **kwargs)
except ValueError:
print('Non JSON output from linter, will not be processed: {}'.format(line))
return
if 'code' in res: def process_line(self, line):
if res['code'].startswith('W'): # Escape slashes otherwise JSON conversion will not work
res['level'] = 'warning' line = line.replace('\\', '\\\\')
try:
res = json.loads(line)
except ValueError:
print('Non JSON output from linter, will not be processed: {}'.format(line))
return
if res['code'] in LINE_OFFSETS: if 'code' in res:
res['lineoffset'] = LINE_OFFSETS[res['code']] if res['code'].startswith('W'):
res['level'] = 'warning'
results.append(result.from_linter(LINTER, **res)) if res['code'] in LINE_OFFSETS:
res['lineoffset'] = LINE_OFFSETS[res['code']]
results.append(result.from_config(self.config, **res))
def run_process(cmdargs): def run(self, *args, **kwargs):
# flake8 seems to handle SIGINT poorly. Handle it here instead # flake8 seems to handle SIGINT poorly. Handle it here instead
# so we can kill the process without a cryptic traceback. # so we can kill the process without a cryptic traceback.
orig = signal.signal(signal.SIGINT, signal.SIG_IGN) orig = signal.signal(signal.SIGINT, signal.SIG_IGN)
proc = ProcessHandler(cmdargs, env=os.environ, ProcessHandlerMixin.run(self, *args, **kwargs)
processOutputLine=process_line) signal.signal(signal.SIGINT, orig)
proc.run()
signal.signal(signal.SIGINT, orig)
try:
proc.wait()
except KeyboardInterrupt:
proc.kill()
def get_flake8_binary(): def get_flake8_binary():
@ -134,7 +129,16 @@ def reinstall_flake8():
return False return False
def lint(files, **lintargs): def run_process(config, cmd):
proc = Flake8Process(config, cmd)
proc.run()
try:
proc.wait()
except KeyboardInterrupt:
proc.kill()
def lint(files, config, **lintargs):
if not reinstall_flake8(): if not reinstall_flake8():
print(FLAKE8_INSTALL_ERROR) print(FLAKE8_INSTALL_ERROR)
@ -157,7 +161,7 @@ def lint(files, **lintargs):
if not os.path.isfile(os.path.join(f, '.flake8')): if not os.path.isfile(os.path.join(f, '.flake8')):
no_config.append(f) no_config.append(f)
continue continue
run_process(cmdargs+[f]) run_process(config, cmdargs+[f])
# XXX For some reason passing in --exclude results in flake8 not using # XXX For some reason passing in --exclude results in flake8 not using
# the local .flake8 file. So for now only pass in --exclude if there # the local .flake8 file. So for now only pass in --exclude if there
@ -167,33 +171,6 @@ def lint(files, **lintargs):
cmdargs += ['--exclude', ','.join(lintargs['exclude'])] cmdargs += ['--exclude', ','.join(lintargs['exclude'])]
if no_config: if no_config:
run_process(cmdargs+no_config) run_process(config, cmdargs+no_config)
return results return results
LINTER = {
'name': "flake8",
'description': "Python linter",
'include': [
'layout/tools/reftest',
'python/mozlint',
'security/manager',
'taskcluster',
'testing/firefox-ui',
'testing/marionette/client',
'testing/marionette/harness',
'testing/marionette/puppeteer',
'testing/mozbase',
'testing/mochitest',
'testing/talos/',
'tools/git',
'tools/lint',
'tools/mercurial',
'toolkit/components/telemetry',
],
'exclude': ['testing/mochitest/pywebsocket'],
'extensions': EXTENSIONS,
'type': 'external',
'payload': lint,
}