summaryrefslogtreecommitdiff
path: root/buildscripts/linter
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2017-04-27 09:50:52 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2017-04-27 09:50:52 -0400
commitc87222f209ac73621274869cc459672cc3ff978c (patch)
treed799b0a234f9a0f021746dd7b8689236d998c7e8 /buildscripts/linter
parentbb1bc2f2695681921a46d4330048ade7d8c204ca (diff)
downloadmongo-c87222f209ac73621274869cc459672cc3ff978c.tar.gz
SERVER-28947 Improve pylinters.py error message when finding linters
Diffstat (limited to 'buildscripts/linter')
-rw-r--r--buildscripts/linter/runner.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/buildscripts/linter/runner.py b/buildscripts/linter/runner.py
index 8b80f93cdbb..0c30207b951 100644
--- a/buildscripts/linter/runner.py
+++ b/buildscripts/linter/runner.py
@@ -20,23 +20,29 @@ def _check_version(linter, cmd_path, args):
try:
cmd = cmd_path + args
- logging.debug(str(cmd))
- output = subprocess.check_output(cmd)
+ logging.info(str(cmd))
+ process_handle = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ output, stderr = process_handle.communicate()
+
+ if process_handle.returncode:
+ logging.info("Version check failed for [%s], return code '%d'." +
+ "Standard Output:\n%s\nStandard Error:\n%s", cmd,
+ process_handle.returncode, output, stderr)
required_version = re.escape(linter.required_version)
+
pattern = r"\b%s\b" % (required_version)
if not re.search(pattern, output):
- logging.info("Linter %s has wrong version for '%s'. Expected '%s', received '%s'",
- linter.cmd_name, cmd, required_version, output)
+ logging.info("Linter %s has wrong version for '%s'. Expected '%s'," +
+ "Standard Output:\n'%s'\nStandard Error:\n%s", linter.cmd_name, cmd,
+ required_version, output, stderr)
return False
+
except OSError as os_error:
# The WindowsError exception is thrown if the command is not found.
# We catch OSError since WindowsError does not exist on non-Windows platforms.
logging.info("Version check command [%s] failed: %s", cmd, os_error)
return False
- except subprocess.CalledProcessError as cpe:
- logging.info("Version check command [%s] failed:\n%s", cmd, cpe.output)
- return False
return True
@@ -89,6 +95,9 @@ def _find_linter(linter, config_dict):
if _check_version(linter, cmd, linter.get_lint_version_cmd_args()):
return base.LinterInstance(linter, cmd)
+ logging.info("First version check failed for linter '%s', trying a different location.",
+ linter.cmd_name)
+
# Check 2: current path
cmd = [linter.cmd_name]
if _check_version(linter, cmd, linter.get_lint_version_cmd_args()):
@@ -105,8 +114,17 @@ def find_linters(linter_list, config_dict):
for linter in linter_list:
linter_instance = _find_linter(linter, config_dict)
if not linter_instance:
- logging.error("Could not find correct version of linter '%s', expected '%s'",
- linter.cmd_name, linter.required_version)
+ logging.error("""\
+Could not find the correct version of linter '%s', expected '%s'. Check your
+PATH environment variable or re-run with --verbose for more information.
+
+To fix, install the needed python modules for both Python 2.7, and Python 3.x:
+ sudo pip2 install -r buildscripts/requirements.txt
+ sudo pip3 install -r buildscripts/requirements.txt
+
+These commands are typically available via packages with names like python-pip,
+python2-pip, and python3-pip. See your OS documentation for help.
+""", linter.cmd_name, linter.required_version)
return None
linter_instances.append(linter_instance)