Mike Frysinger | 5329779 | 2019-08-20 21:32:33 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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. |
| 5 | |
| 6 | """Chromium wrapper for pylint for passing args via stdin. |
| 7 | |
| 8 | This will be executed by vpython with the right pylint versions. |
| 9 | """ |
| 10 | |
| 11 | from __future__ import print_function |
| 12 | |
| 13 | import os |
| 14 | import sys |
| 15 | |
| 16 | from pylint import lint |
| 17 | |
| 18 | |
| 19 | HERE = os.path.dirname(os.path.abspath(__file__)) |
| 20 | PYLINT = os.path.join(HERE, 'pylint_main.py') |
| 21 | RC_FILE = os.path.join(HERE, 'pylintrc') |
| 22 | |
| 23 | ARGS_ON_STDIN = '--args-on-stdin' |
| 24 | |
| 25 | |
| 26 | def main(argv): |
| 27 | """Our main wrapper.""" |
| 28 | # Add support for a custom mode where arguments are fed line by line on |
| 29 | # stdin. This allows us to get around command line length limitations. |
| 30 | if ARGS_ON_STDIN in argv: |
| 31 | argv = [x for x in argv if x != ARGS_ON_STDIN] |
| 32 | argv.extend(x.strip() for x in sys.stdin) |
| 33 | |
| 34 | # We prepend the command-line with the depot_tools rcfile. If another rcfile |
| 35 | # is to be used, passing --rcfile a second time on the command-line will work |
| 36 | # fine. |
| 37 | if os.path.isfile(RC_FILE): |
| 38 | # The file can be removed to test 'normal' pylint behavior. |
| 39 | argv.insert(0, '--rcfile=%s' % RC_FILE) |
| 40 | |
| 41 | lint.Run(argv) |
| 42 | |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | sys.exit(main(sys.argv[1:])) |