pylint_main.py 2.2 KB

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