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 <jojwang@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Mike Frysinger
2025-01-06 17:39:37 -08:00
committed by LUCI CQ
parent 1dd73cd467
commit 423f1e1914

View File

@@ -17,6 +17,16 @@ RC_FILE = os.path.join(HERE, 'pylintrc')
ARGS_ON_STDIN = '--args-on-stdin' 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): def main(argv):
"""Our main wrapper.""" """Our main wrapper."""
# Add support for a custom mode where arguments are fed line by line on # 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 = [x for x in argv if x != ARGS_ON_STDIN]
argv.extend(x.strip() for x in sys.stdin) argv.extend(x.strip() for x in sys.stdin)
rc_file = find_rcfile()
# Set default config options with the PYLINTRC environment variable. This # Set default config options with the PYLINTRC environment variable. This
# will allow overriding with "more local" config file options, such as a # will allow overriding with "more local" config file options, such as a
# local "pylintrc" file, the "--rcfile" command-line flag, or an existing # 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 # 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 # file resolution, which would include the "more global" options that are
# normally overridden by the depot_tools config. # 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 # This import has to happen after PYLINTRC is set because the module tries
# to resolve the config file location on load. # to resolve the config file location on load.