Bug 1652503: [mozlint] Always use vendored yamllint; r=ahal
authorTom Prince <mozilla@hocat.ca>
Thu, 23 Jul 2020 14:55:42 +0000
changeset 541783 8e015d90d36bda678ea3f8629a5698902e58c912
parent 541782 b4ea018b2b835e72043a6472f75220c8f0fb9073
child 541784 fd62c070359b29bf2e9bb72f194382119cf4f931
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1652503
milestone80.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 1652503: [mozlint] Always use vendored yamllint; r=ahal Differential Revision: https://phabricator.services.mozilla.com/D84642
tools/lint/test/python.ini
tools/lint/test/test_yaml.py
tools/lint/yamllint_/__init__.py
--- a/tools/lint/test/python.ini
+++ b/tools/lint/test/python.ini
@@ -14,17 +14,16 @@ skip-if = os == "win"
 [test_file_whitespace.py]
 [test_file_license.py]
 [test_lintpref.py]
 [test_shellcheck.py]
 [test_rst.py]
 [test_codespell.py]
 skip-if = os == "win" || os == "mac"  # codespell installed on Linux
 [test_yaml.py]
-skip-if = os == "win" || os == "mac"  # fails with No module named 'pkg_resources'
 [test_clippy.py]
 skip-if = os == "win" || os == "mac"  # only installed on Linux
 [test_rustfmt.py]
 skip-if = os == "win" || os == "mac"  # only installed on Linux
 [test_clang_format.py]
 skip-if = os == "win" || os == "mac"  # only installed on Linux
 [test_pylint.py]
 skip-if = os == "win" || os == "mac"  # only installed on linux
--- a/tools/lint/test/test_yaml.py
+++ b/tools/lint/test/test_yaml.py
@@ -1,16 +1,11 @@
-import pytest
 import mozunit
-from mozfile import which
 
 LINTER = "yaml"
-pytestmark = pytest.mark.skipif(
-    not which("yamllint"), reason="yamllint is not installed"
-)
 
 
 def test_basic(lint, paths):
     results = lint(paths())
 
     assert len(results) == 3
 
     assert "line too long (122 > 80 characters)" in results[0].message
--- a/tools/lint/yamllint_/__init__.py
+++ b/tools/lint/yamllint_/__init__.py
@@ -1,18 +1,20 @@
 # 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
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import re
 import os
-import subprocess
+import sys
 from collections import defaultdict
 
-from mozfile import which
+from mozbuild.base import MozbuildObject
+
+topsrcdir = MozbuildObject.from_environment().topsrcdir
 
 from mozlint import result
 from mozlint.pathutils import get_ancestors_by_name
 from mozlint.util.implementation import LintProcess
 
 
 YAMLLINT_FORMAT_REGEX = re.compile("(.*):(.*):(.*): \[(error|warning)\] (.*) \((.*)\)$")
 
@@ -35,48 +37,20 @@ class YAMLLintProcess(LintProcess):
             "lineno": line,
             "column": col,
             "rule": code,
         }
 
         results.append(result.from_config(self.config, **res))
 
 
-def get_yamllint_binary(mc_root):
-    """
-    Returns the path of the first yamllint binary available
-    if not found returns None
-    """
-    binary = os.environ.get("YAMLLINT")
-    if binary:
-        return binary
-
-    # yamllint is vendored in mozilla-central: let's use this
-    # if no environment variable is found.
-    return os.path.join(mc_root, "third_party", "python", "yamllint", "yamllint")
-
+def get_yamllint_version():
+    from yamllint import APP_VERSION
 
-def get_yamllint_version(binary):
-    return subprocess.check_output(
-        [which("python"), binary, "--version"],
-        universal_newlines=True,
-        stderr=subprocess.STDOUT,
-    )
-
-
-def _run_pip(*args):
-    """
-    Helper function that runs pip with subprocess
-    """
-    try:
-        subprocess.check_output(["pip"] + list(args), stderr=subprocess.STDOUT)
-        return True
-    except subprocess.CalledProcessError as e:
-        print(e.output)
-        return False
+    return APP_VERSION
 
 
 def run_process(config, cmd):
     proc = YAMLLintProcess(config, cmd)
     proc.run()
     try:
         proc.wait()
     except KeyboardInterrupt:
@@ -90,21 +64,28 @@ def gen_yamllint_args(cmdargs, paths=Non
     if conf_file and conf_file != "default":
         return args + ["-c", conf_file] + paths
     return args + paths
 
 
 def lint(files, config, **lintargs):
     log = lintargs["log"]
 
-    binary = get_yamllint_binary(lintargs["root"])
+    log.debug("Version: {}".format(get_yamllint_version()))
 
-    log.debug("Version: {}".format(get_yamllint_version(binary)))
-
-    cmdargs = [which("python"), binary, "-f", "parsable"]
+    cmdargs = [
+        sys.executable,
+        os.path.join(topsrcdir, "mach"),
+        "python",
+        "--",
+        "-m",
+        "yamllint",
+        "-f",
+        "parsable",
+    ]
     log.debug("Command: {}".format(" ".join(cmdargs)))
 
     config = config.copy()
     config["root"] = lintargs["root"]
 
     # Run any paths with a .yamllint file in the directory separately so
     # it gets picked up. This means only .yamllint files that live in
     # directories that are explicitly included will be considered.