check_all_python.py 853 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python2
  2. # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. import glob
  4. # Checks that all python files in the repository are at least free of syntax
  5. # errors. This provides a minimal pre-/post-commit check for python file
  6. # modifications.
  7. filenames = []
  8. # Avoid scanning all of ./ because there might be other external repos
  9. # linked in.
  10. for base in ["buckifier", "build_tools", "coverage", "tools"]:
  11. # Clean this up when we finally upgrade to Python 3
  12. for suff in ["*", "*/*", "*/*/*"]:
  13. filenames += glob.glob(base + "/" + suff + ".py")
  14. for filename in filenames:
  15. source = open(filename, 'r').read() + '\n'
  16. # Parses and syntax checks the file, throwing on error. (No pyc written.)
  17. _ = compile(source, filename, 'exec')
  18. print("No syntax errors in {0} .py files".format(len(filenames)))