Bug 1460402 - Update the codespell support to use pip instead of the package r?ahal
MozReview-Commit-ID: J4wS7s9sWFe
--- a/tools/lint/spell/__init__.py
+++ b/tools/lint/spell/__init__.py
@@ -11,32 +11,39 @@ import re
# Py3/Py2 compatibility.
try:
from json.decoder import JSONDecodeError
except ImportError:
JSONDecodeError = ValueError
from mozlint import result
+from mozlint.util import pip
from mozprocess import ProcessHandlerMixin
+here = os.path.abspath(os.path.dirname(__file__))
+CODESPELL_REQUIREMENTS_PATH = os.path.join(here, 'codespell_requirements.txt')
CODESPELL_NOT_FOUND = """
-Unable to locate codespell, please ensure it is installed and in
-your PATH or set the CODESPELL environment variable.
+Could not find codespell! Install codespell and try again.
+
+ $ pip install -U --require-hashes -r {}
+""".strip().format(CODESPELL_REQUIREMENTS_PATH)
+
-https://github.com/lucasdemarchi/codespell or your system's package manager.
-""".strip()
+CODESPELL_INSTALL_ERROR = """
+Unable to install correct version of codespell
+Try to install it manually with:
+ $ pip install -U --require-hashes -r {}
+""".strip().format(CODESPELL_REQUIREMENTS_PATH)
results = []
CODESPELL_FORMAT_REGEX = re.compile(r'(.*):(.*): (.*) ==> (.*)$')
-here = os.path.abspath(os.path.dirname(__file__))
-
class CodespellProcess(ProcessHandlerMixin):
def __init__(self, config, *args, **kwargs):
self.config = config
kwargs['processOutputLine'] = [self.process_line]
ProcessHandlerMixin.__init__(self, *args, **kwargs)
def process_line(self, line):
@@ -86,16 +93,20 @@ def get_codespell_binary():
try:
return which.which('codespell')
except which.WhichError:
return None
def lint(paths, config, fix=None, **lintargs):
+ if not pip.reinstall_program(CODESPELL_REQUIREMENTS_PATH):
+ print(CODESPELL_INSTALL_ERROR)
+ return 1
+
binary = get_codespell_binary()
if not binary:
print(CODESPELL_NOT_FOUND)
if 'MOZ_AUTOMATION' in os.environ:
return 1
return []
@@ -105,17 +116,18 @@ def lint(paths, config, fix=None, **lint
'--disable-colors',
# Silence some warnings:
# 1: disable warnings about wrong encoding
# 2: disable warnings about binary file
# 4: shut down warnings about automatic fixes
# that were disabled in dictionary.
'--quiet-level=4',
'--ignore-words=' + exclude_list,
- '--skip=exclude-list.txt',
+ # Ignore dictonnaries
+ '--skip=*.dic',
]
if fix:
cmd_args.append('--write-changes')
base_command = cmd_args + paths
run_process(config, base_command)
new file mode 100644
--- /dev/null
+++ b/tools/lint/spell/codespell_requirements.txt
@@ -0,0 +1,2 @@
+codespell==1.12.0 \
+ --hash=sha256:f547ef6ea3af4569b0a4d3ef106ef6403f6ee574afdaa8e332650aea87301daf