2
1

pycompile.py 698 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python
  2. # Wrapper for python2 and python3 around compileall to raise exception
  3. # when a python byte code generation failed.
  4. #
  5. # Inspired from:
  6. # http://stackoverflow.com/questions/615632/how-to-detect-errors-from-compileall-compile-dir
  7. from __future__ import print_function
  8. import sys
  9. import py_compile
  10. import compileall
  11. class ReportProblem:
  12. def __nonzero__(self):
  13. type, value, traceback = sys.exc_info()
  14. if type is not None and issubclass(type, py_compile.PyCompileError):
  15. print("Cannot compile %s" %value.file)
  16. raise value
  17. return 1
  18. report_problem = ReportProblem()
  19. compileall.compile_dir(sys.argv[1], quiet=report_problem)