aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSen Jiang <senj@google.com>2017-08-17 01:31:10 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-08-17 01:31:10 +0000
commite03c05667563ebbb167902dbf27b1ce4544294e9 (patch)
treea919e102b63ce05e604169b54903e4c587de7cdf
parentfe49310df3a905d60ffdc123ad15f826e289e8e5 (diff)
parent2e3a82f3350baa64f24478baa257dd59fc8e6068 (diff)
downloadrepohooks-e03c05667563ebbb167902dbf27b1ce4544294e9.tar.gz
pylint: support per-repo pylintrc files. am: 6d58a8136d am: 6abc478494 am: 97972e149d
am: 2e3a82f335 Change-Id: Idc8d26d60ec9ef5ebd9c32ecdd1200c231ced73a
-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