Bug 1460402 - Update the codespell support to use pip instead of the package r=ahal
☠☠ backed out by 5a8eea8a92bb ☠ ☠
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 09 May 2018 21:56:43 +0200
changeset 417809 3676e913dbffe199ec57ec84f97545e749291ad9
parent 417808 bb12ffd4b96e318f1e492661efb9747862988c77
child 417810 c2e8fbd72ca649e29403c31c8cee9e36cf83ebd6
push id33980
push userebalazs@mozilla.com
push dateFri, 11 May 2018 09:35:12 +0000
treeherdermozilla-central@8e9a4a323f0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1460402
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1460402 - Update the codespell support to use pip instead of the package r=ahal MozReview-Commit-ID: J4wS7s9sWFe
tools/lint/spell/__init__.py
tools/lint/spell/codespell_requirements.txt
--- 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 []
 
new file mode 100644
--- /dev/null
+++ b/tools/lint/spell/codespell_requirements.txt
@@ -0,0 +1,2 @@
+codespell==1.12.0 \
+    --hash=sha256:f547ef6ea3af4569b0a4d3ef106ef6403f6ee574afdaa8e332650aea87301daf