blob: d03021ddbef2834109eb122e8faa27d634bc4d61 [file] [log] [blame]
Mike Frysinger53297792019-08-20 21:32:33 +00001#!/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
8This will be executed by vpython with the right pylint versions.
9"""
10
11from __future__ import print_function
12
13import os
14import sys
15
Mike Frysinger53297792019-08-20 21:32:33 +000016HERE = os.path.dirname(os.path.abspath(__file__))
17PYLINT = os.path.join(HERE, 'pylint_main.py')
18RC_FILE = os.path.join(HERE, 'pylintrc')
19
20ARGS_ON_STDIN = '--args-on-stdin'
21
22
23def main(argv):
24 """Our main wrapper."""
25 # Add support for a custom mode where arguments are fed line by line on
26 # stdin. This allows us to get around command line length limitations.
27 if ARGS_ON_STDIN in argv:
28 argv = [x for x in argv if x != ARGS_ON_STDIN]
29 argv.extend(x.strip() for x in sys.stdin)
30
Michael Mossae8b2c62021-02-23 17:24:56 +000031 # Set default config options with the PYLINTRC environment variable. This will
32 # allow overriding with "more local" config file options, such as a local
33 # "pylintrc" file, the "--rcfile" command-line flag, or an existing PYLINTRC.
34 #
35 # Note that this is not quite the same thing as replacing pylint's built-in
36 # defaults, since, based on config file precedence, it will not be overridden
37 # by "more global" config file options, such as ~/.pylintrc,
38 # ~/.config/pylintrc, or /etc/pylintrc. This is generally the desired
39 # behavior, since we want to enforce these defaults in most cases, but allow
40 # them to be overridden for specific code or repos.
41 #
42 # If someone really doesn't ever want the depot_tools pylintrc, they can set
43 # their own PYLINTRC, or set an empty PYLINTRC to use pylint's normal config
44 # file resolution, which would include the "more global" options that are
45 # normally overridden by the depot_tools config.
46 if os.path.isfile(RC_FILE) and 'PYLINTRC' not in os.environ:
47 os.environ['PYLINTRC'] = RC_FILE
Mike Frysinger53297792019-08-20 21:32:33 +000048
Michael Mossae8b2c62021-02-23 17:24:56 +000049 # This import has to happen after PYLINTRC is set because the module tries to
50 # resolve the config file location on load.
51 from pylint import lint # pylint: disable=bad-option-value,import-outside-toplevel
Mike Frysinger53297792019-08-20 21:32:33 +000052 lint.Run(argv)
53
54
55if __name__ == '__main__':
56 sys.exit(main(sys.argv[1:]))