From 423f1e1914ab4aa7b2bdf804e216d4c097853ba2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 6 Jan 2025 17:39:37 -0800 Subject: [PATCH] pylint: support versioned pylintrc files The presubmit code already picks pylintrc-$VER for pylint-$VER files, but running pylint-$VER directly does not. This is confusing for people where `git cl presubmit` does one thing, but `./pylint-$VER` does another. Change-Id: I074c34db43cbc383ecab4ff3f9a71b8f2b611d15 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6150452 Reviewed-by: Joanna Wang Commit-Queue: Mike Frysinger --- pylint_main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pylint_main.py b/pylint_main.py index a146370e5d..d83f60fc2f 100755 --- a/pylint_main.py +++ b/pylint_main.py @@ -17,6 +17,16 @@ RC_FILE = os.path.join(HERE, 'pylintrc') ARGS_ON_STDIN = '--args-on-stdin' +def find_rcfile() -> str: + """Locate the config file for this wrapper.""" + arg0 = os.path.basename(sys.argv[0]) + if arg0.startswith('pylint-'): + rc_file = RC_FILE + '-' + arg0.split('-', 1)[1] + if os.path.exists(rc_file): + return rc_file + return RC_FILE + + def main(argv): """Our main wrapper.""" # Add support for a custom mode where arguments are fed line by line on @@ -25,6 +35,8 @@ def main(argv): argv = [x for x in argv if x != ARGS_ON_STDIN] argv.extend(x.strip() for x in sys.stdin) + rc_file = find_rcfile() + # Set default config options with the PYLINTRC environment variable. This # will allow overriding with "more local" config file options, such as a # local "pylintrc" file, the "--rcfile" command-line flag, or an existing @@ -41,7 +53,7 @@ def main(argv): # their own PYLINTRC, or set an empty PYLINTRC to use pylint's normal config # file resolution, which would include the "more global" options that are # normally overridden by the depot_tools config. - os.environ.setdefault('PYLINTRC', RC_FILE) + os.environ.setdefault('PYLINTRC', rc_file) # This import has to happen after PYLINTRC is set because the module tries # to resolve the config file location on load.