зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1580280
- [lint] Support Python 3 in other lint integrations r=sylvestre
Differential Revision: https://phabricator.services.mozilla.com/D45440 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
795035dba3
Коммит
885bdd32e7
|
@ -67,4 +67,5 @@ codespell:
|
|||
support-files:
|
||||
- 'tools/lint/spell/**'
|
||||
type: external
|
||||
setup: spell:setup
|
||||
payload: spell:lint
|
||||
|
|
|
@ -18,11 +18,11 @@ def lint(paths, config, fix=None, **lintargs):
|
|||
hasFix = False
|
||||
content_to_write = []
|
||||
for i, line in enumerate(open_file):
|
||||
if line.endswith(" \n"):
|
||||
if line.endswith(b" \n"):
|
||||
# We found a trailing whitespace
|
||||
if fix:
|
||||
# We want to fix it, strip the trailing spaces
|
||||
content_to_write.append(line.rstrip() + "\n")
|
||||
content_to_write.append(line.rstrip() + b"\n")
|
||||
hasFix = True
|
||||
else:
|
||||
res = {'path': f,
|
||||
|
@ -37,7 +37,7 @@ def lint(paths, config, fix=None, **lintargs):
|
|||
if hasFix:
|
||||
# Only update the file when we found a change to make
|
||||
with open(f, 'wb') as open_file_to_write:
|
||||
open_file_to_write.write("".join(content_to_write))
|
||||
open_file_to_write.write(b"".join(content_to_write))
|
||||
|
||||
# We are still using the same fp, let's return to the first
|
||||
# line
|
||||
|
@ -46,7 +46,7 @@ def lint(paths, config, fix=None, **lintargs):
|
|||
# at least one \r\n
|
||||
content = open_file.read()
|
||||
|
||||
if "\r\n" in content:
|
||||
if b"\r\n" in content:
|
||||
if fix:
|
||||
# replace \r\n by \n
|
||||
content = content.replace(b'\r\n', b'\n')
|
||||
|
|
|
@ -8,6 +8,7 @@ import os
|
|||
|
||||
from mozlint import result
|
||||
from mozlint.pathutils import expand_exclusions
|
||||
from six import PY2
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
@ -37,7 +38,7 @@ def load_valid_license():
|
|||
with open(license_list) as f:
|
||||
l = f.readlines()
|
||||
# Remove the empty lines
|
||||
return filter(bool, [x.replace('\n', '') for x in l])
|
||||
return list(filter(bool, [x.replace('\n', '') for x in l]))
|
||||
|
||||
|
||||
def is_valid_license(licenses, filename):
|
||||
|
@ -45,15 +46,15 @@ def is_valid_license(licenses, filename):
|
|||
From a given file, check if we can find the license patterns
|
||||
in the X first lines of the file
|
||||
"""
|
||||
nb_lines = 10
|
||||
with open(filename) as myfile:
|
||||
head = myfile.readlines(nb_lines)
|
||||
kwargs = {} if PY2 else {'errors': 'replace'}
|
||||
with open(filename, 'r', **kwargs) as myfile:
|
||||
contents = myfile.read()
|
||||
# Empty files don't need a license.
|
||||
if not head:
|
||||
if not contents:
|
||||
return True
|
||||
|
||||
for l in licenses:
|
||||
if l.lower().strip() in ''.join(head).lower():
|
||||
if l.lower().strip() in contents.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# 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/.
|
||||
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
@ -82,8 +82,9 @@ def lint(files, config, **lintargs):
|
|||
proc = subprocess.Popen(
|
||||
cmdargs, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=os.environ
|
||||
)
|
||||
env=os.environ,
|
||||
universal_newlines=True,
|
||||
)
|
||||
all_errors = proc.communicate()[1]
|
||||
for errors in all_errors.split("\n"):
|
||||
if len(errors) > 1:
|
||||
|
|
|
@ -114,7 +114,9 @@ def is_old_rustfmt(binary):
|
|||
"""
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
[binary, " --version"], stderr=subprocess.STDOUT
|
||||
[binary, " --version"],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
output = e.output
|
||||
|
|
|
@ -18,6 +18,7 @@ from mozfile import which
|
|||
from mozlint import result
|
||||
from mozlint.util import pip
|
||||
from mozprocess import ProcessHandlerMixin
|
||||
from six import PY3
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
CODESPELL_REQUIREMENTS_PATH = os.path.join(here, 'codespell_requirements.txt')
|
||||
|
@ -43,7 +44,10 @@ CODESPELL_FORMAT_REGEX = re.compile(r'(.*):(.*): (.*) ==> (.*)$')
|
|||
class CodespellProcess(ProcessHandlerMixin):
|
||||
def __init__(self, config, *args, **kwargs):
|
||||
self.config = config
|
||||
kwargs['processOutputLine'] = [self.process_line]
|
||||
kwargs = {
|
||||
'processOutputLine': [self.process_line],
|
||||
'universal_newlines': PY3,
|
||||
}
|
||||
ProcessHandlerMixin.__init__(self, *args, **kwargs)
|
||||
|
||||
def process_line(self, line):
|
||||
|
@ -93,14 +97,14 @@ def get_codespell_binary():
|
|||
return which('codespell')
|
||||
|
||||
|
||||
def lint(paths, config, fix=None, **lintargs):
|
||||
|
||||
def setup(root, **lintargs):
|
||||
if not pip.reinstall_program(CODESPELL_REQUIREMENTS_PATH):
|
||||
print(CODESPELL_INSTALL_ERROR)
|
||||
return 1
|
||||
|
||||
binary = get_codespell_binary()
|
||||
|
||||
def lint(paths, config, fix=None, **lintargs):
|
||||
binary = get_codespell_binary()
|
||||
if not binary:
|
||||
print(CODESPELL_NOT_FOUND)
|
||||
if 'MOZ_AUTOMATION' in os.environ:
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
codespell==1.16.0 \
|
||||
--hash=sha256:a81780122f955002d032a9a9c55e2305c6f252a530d8682ed5c3d0580f93d9b8 \
|
||||
--hash=sha256:bf3b7c83327aefd26fe718527baa9bd61016e86db91a8123c0ef9c150fa02de9
|
||||
|
|
|
@ -14,6 +14,7 @@ from mozfile import which
|
|||
from mozlint import result
|
||||
from mozlint.pathutils import get_ancestors_by_name
|
||||
from mozprocess import ProcessHandlerMixin
|
||||
from six import string_types
|
||||
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
|
@ -112,7 +113,7 @@ def run_process(config, cmd):
|
|||
|
||||
def gen_yamllint_args(cmdargs, paths=None, conf_file=None):
|
||||
args = cmdargs[:]
|
||||
if isinstance(paths, basestring):
|
||||
if isinstance(paths, string_types):
|
||||
paths = [paths]
|
||||
if conf_file and conf_file != 'default':
|
||||
return args + ['-c', conf_file] + paths
|
||||
|
|
Загрузка…
Ссылка в новой задаче