run_devutils_pylint.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2019 The ungoogled-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. """Run Pylint over devutils"""
  6. import argparse
  7. import sys
  8. from pathlib import Path
  9. from run_other_pylint import ChangeDir, run_pylint
  10. def main():
  11. """CLI entrypoint"""
  12. parser = argparse.ArgumentParser(description='Run Pylint over devutils')
  13. parser.add_argument('--hide-fixme', action='store_true', help='Hide "fixme" Pylint warnings.')
  14. parser.add_argument('--show-locally-disabled',
  15. action='store_true',
  16. help='Show "locally-disabled" Pylint warnings.')
  17. args = parser.parse_args()
  18. disables = [
  19. 'wrong-import-position',
  20. 'bad-continuation',
  21. 'duplicate-code',
  22. ]
  23. if args.hide_fixme:
  24. disables.append('fixme')
  25. if not args.show_locally_disabled:
  26. disables.append('locally-disabled')
  27. pylint_options = [
  28. '--disable={}'.format(','.join(disables)),
  29. '--jobs=4',
  30. '--score=n',
  31. '--persistent=n',
  32. ]
  33. ignore_prefixes = [
  34. ('third_party', ),
  35. ]
  36. sys.path.insert(1, str(Path(__file__).resolve().parent.parent / 'utils'))
  37. sys.path.insert(2, str(Path(__file__).resolve().parent.parent / 'devutils' / 'third_party'))
  38. with ChangeDir(Path(__file__).parent):
  39. result = run_pylint(
  40. Path(),
  41. pylint_options,
  42. ignore_prefixes=ignore_prefixes,
  43. )
  44. sys.path.pop(2)
  45. sys.path.pop(1)
  46. if not result:
  47. sys.exit(1)
  48. sys.exit(0)
  49. if __name__ == '__main__':
  50. main()