Josip Sokcevic | 4de5dea | 2022-03-23 21:15:14 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 2 | # Copyright 2019 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 5 | """Chromium wrapper for pylint for passing args via stdin. |
| 6 | |
| 7 | This will be executed by vpython with the right pylint versions. |
| 8 | """ |
| 9 | |
Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 10 | import os |
| 11 | import sys |
| 12 | |
Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 13 | HERE = os.path.dirname(os.path.abspath(__file__)) |
| 14 | PYLINT = os.path.join(HERE, 'pylint_main.py') |
| 15 | RC_FILE = os.path.join(HERE, 'pylintrc') |
| 16 | |
| 17 | ARGS_ON_STDIN = '--args-on-stdin' |
| 18 | |
| 19 | |
| 20 | def main(argv): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 21 | """Our main wrapper.""" |
| 22 | # Add support for a custom mode where arguments are fed line by line on |
| 23 | # stdin. This allows us to get around command line length limitations. |
| 24 | if ARGS_ON_STDIN in argv: |
| 25 | argv = [x for x in argv if x != ARGS_ON_STDIN] |
| 26 | argv.extend(x.strip() for x in sys.stdin) |
Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 27 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 28 | # Set default config options with the PYLINTRC environment variable. This |
| 29 | # will allow overriding with "more local" config file options, such as a |
| 30 | # local "pylintrc" file, the "--rcfile" command-line flag, or an existing |
| 31 | # PYLINTRC. |
| 32 | # |
| 33 | # Note that this is not quite the same thing as replacing pylint's built-in |
| 34 | # defaults, since, based on config file precedence, it will not be |
| 35 | # overridden by "more global" config file options, such as ~/.pylintrc, |
| 36 | # ~/.config/pylintrc, or /etc/pylintrc. This is generally the desired |
| 37 | # behavior, since we want to enforce these defaults in most cases, but allow |
| 38 | # them to be overridden for specific code or repos. |
| 39 | # |
| 40 | # If someone really doesn't ever want the depot_tools pylintrc, they can set |
| 41 | # their own PYLINTRC, or set an empty PYLINTRC to use pylint's normal config |
| 42 | # file resolution, which would include the "more global" options that are |
| 43 | # normally overridden by the depot_tools config. |
| 44 | if os.path.isfile(RC_FILE) and 'PYLINTRC' not in os.environ: |
| 45 | os.environ['PYLINTRC'] = RC_FILE |
Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 46 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 47 | # This import has to happen after PYLINTRC is set because the module tries |
| 48 | # to resolve the config file location on load. |
| 49 | from pylint import lint # pylint: disable=bad-option-value,import-outside-toplevel |
| 50 | lint.Run(argv) |
Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | if __name__ == '__main__': |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 54 | sys.exit(main(sys.argv[1:])) |