aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2017-11-10 18:23:43 -0500
committerMike Frysinger <vapier@google.com>2017-11-10 18:27:20 -0500
commitb9006f94efcbd7fd302a318ad6427a1ab57f8a3f (patch)
tree0b77e398ff3e5516cc8ba4d33971803d721238f1 /tools
parent2ef213ca32302bff97839cee7d58942f8bd244eb (diff)
downloadrepohooks-b9006f94efcbd7fd302a318ad6427a1ab57f8a3f.tar.gz
pylint: handle missing pylint better
If you don't have pylint installed, trying to run pylint will result in confusuing output: Traceback (most recent call last): File "./tools/pylint.py", line 69, in <module> sys.exit(main(sys.argv[1:])) File "./tools/pylint.py", line 65, in main os.execvp(cmd[0], cmd) File "/usr/lib/python2.7/os.py", line 346, in execvp _execvpe(file, args) File "/usr/lib/python2.7/os.py", line 382, in _execvpe func(fullname, *argrest) OSError: [Errno 2] No such file or directory Rather than make people guess that they need to install pylint, catch this error and display something more user friendly: pylint.py: unable to run `pylint`: [Errno 2] No such file or directory pylint.py: Try installing pylint: sudo apt-get install pylint Bug: None Test: `./tools/pylint.py tools/cpplint.py --executable-path asdf` no longer barfs Change-Id: I7a259e2d950d66855c0dea367e035fe6adc4ce93
Diffstat (limited to 'tools')
-rwxr-xr-xtools/pylint.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tools/pylint.py b/tools/pylint.py
index 6091c1d..1c8e6f7 100755
--- a/tools/pylint.py
+++ b/tools/pylint.py
@@ -19,12 +19,15 @@
from __future__ import print_function
import argparse
+import errno
import os
import sys
+
DEFAULT_PYLINTRC_PATH = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'pylintrc')
+
def get_parser():
"""Return a command line parser."""
parser = argparse.ArgumentParser(description=__doc__)
@@ -62,7 +65,17 @@ def main(argv):
if opts.init_hook:
cmd += ['--init-hook', opts.init_hook]
- os.execvp(cmd[0], cmd)
+ try:
+ os.execvp(cmd[0], cmd)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ print('%s: unable to run `%s`: %s' % (__file__, cmd[0], e),
+ file=sys.stderr)
+ print('%s: Try installing pylint: sudo apt-get install pylint' %
+ (__file__,), file=sys.stderr)
+ return 1
+ else:
+ raise
if __name__ == '__main__':