aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSen Jiang <senj@google.com>2017-08-15 18:08:07 -0700
committerSen Jiang <senj@google.com>2017-08-16 12:57:28 -0700
commit6d58a8136dc411a9d2036f064ad764f28848d83e (patch)
treea919e102b63ce05e604169b54903e4c587de7cdf
parent4c4e78c4d9b52a1a5c5ed11c39ab36d258037a2c (diff)
downloadrepohooks-6d58a8136dc411a9d2036f064ad764f28848d83e.tar.gz
pylint: support per-repo pylintrc files.
Use the pylintrc in the repo if exists, otherwise fallback to the default one. Bug: None Test: repo upload Change-Id: I33cb428ceab56215e375b725da673ffed21cd928
-rw-r--r--README.md2
-rwxr-xr-xtools/pylint.py14
2 files changed, 10 insertions, 6 deletions
diff --git a/README.md b/README.md
index ff97bb4..f25b979 100644
--- a/README.md
+++ b/README.md
@@ -222,7 +222,7 @@ These are notes for people updating the `pre-upload.py` hook itself:
## TODO/Limitations
-* `pylint` should support per-repo pylintrc files.
+* `pylint` should support per-directory pylintrc files.
* Some checkers operate on the files as they exist in the filesystem. This is
not easy to fix because the linters require not just the modified file but the
entire repo in order to perform full checks. e.g. `pylint` needs to know what
diff --git a/tools/pylint.py b/tools/pylint.py
index 45afe64..6091c1d 100755
--- a/tools/pylint.py
+++ b/tools/pylint.py
@@ -45,12 +45,16 @@ def main(argv):
parser = get_parser()
opts, unknown = parser.parse_known_args(argv)
- pylintrc = DEFAULT_PYLINTRC_PATH if not opts.no_rcfile else None
-
cmd = [opts.executable_path]
- if pylintrc:
- # If we pass a non-existent rcfile to pylint, it'll happily ignore it.
- assert os.path.exists(pylintrc), 'Could not find %s' % pylintrc
+ if not opts.no_rcfile:
+ # We assume pylint is running in the top directory of the project,
+ # so load the pylintrc file from there if it's available.
+ pylintrc = os.path.abspath('pylintrc')
+ if not os.path.exists(pylintrc):
+ pylintrc = DEFAULT_PYLINTRC_PATH
+ # If we pass a non-existent rcfile to pylint, it'll happily ignore
+ # it.
+ assert os.path.exists(pylintrc), 'Could not find %s' % pylintrc
cmd += ['--rcfile', pylintrc]
cmd += unknown + opts.files