From b86503f9802e02cd973f3e14fbf501e9ba2f25c2 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 9 May 2018 21:56:43 +0200 Subject: [PATCH] Bug 1460402 - Update the codespell support to use pip instead of the package r=ahal MozReview-Commit-ID: J4wS7s9sWFe --HG-- extra : rebase_source : 4666a3e5bab6ee5ca95fcc31da4ef625e46e2d59 --- tools/lint/spell/__init__.py | 23 +++++++++++++++------ tools/lint/spell/codespell_requirements.txt | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 tools/lint/spell/codespell_requirements.txt diff --git a/tools/lint/spell/__init__.py b/tools/lint/spell/__init__.py index 6f1edf0fd24a..bc6d7dae98de 100644 --- a/tools/lint/spell/__init__.py +++ b/tools/lint/spell/__init__.py @@ -16,22 +16,29 @@ 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. -https://github.com/lucasdemarchi/codespell or your system's package manager. -""".strip() + $ pip install -U --require-hashes -r {} +""".strip().format(CODESPELL_REQUIREMENTS_PATH) + + +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): @@ -91,6 +98,10 @@ def get_codespell_binary(): 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: diff --git a/tools/lint/spell/codespell_requirements.txt b/tools/lint/spell/codespell_requirements.txt new file mode 100644 index 000000000000..0bf7eafc2230 --- /dev/null +++ b/tools/lint/spell/codespell_requirements.txt @@ -0,0 +1,2 @@ +codespell==1.12.0 \ + --hash=sha256:f547ef6ea3af4569b0a4d3ef106ef6403f6ee574afdaa8e332650aea87301daf