pylint_main.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. """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. from pylint import lint
  12. HERE = os.path.dirname(os.path.abspath(__file__))
  13. PYLINT = os.path.join(HERE, 'pylint_main.py')
  14. RC_FILE = os.path.join(HERE, 'pylintrc')
  15. ARGS_ON_STDIN = '--args-on-stdin'
  16. def main(argv):
  17. """Our main wrapper."""
  18. # Add support for a custom mode where arguments are fed line by line on
  19. # stdin. This allows us to get around command line length limitations.
  20. if ARGS_ON_STDIN in argv:
  21. argv = [x for x in argv if x != ARGS_ON_STDIN]
  22. argv.extend(x.strip() for x in sys.stdin)
  23. # We prepend the command-line with the depot_tools rcfile. If another rcfile
  24. # is to be used, passing --rcfile a second time on the command-line will work
  25. # fine.
  26. if os.path.isfile(RC_FILE):
  27. # The file can be removed to test 'normal' pylint behavior.
  28. argv.insert(0, '--rcfile=%s' % RC_FILE)
  29. lint.Run(argv)
  30. if __name__ == '__main__':
  31. sys.exit(main(sys.argv[1:]))