The Python interpreter can be started with -tt to raise a TabError exception if the interpreted file has inconsistent tab usage.
I’m trying to write a pre-commit hook for SVN that rejects files that raise this exception. I can pass the file being committed to python -tt but my problem is that the file is also executed, besides being checked. Is there a way to tell Python “just analyze the file, don’t run it”? Or maybe some other approach would be better for accomplishing what I want.
You can do this using the
py_compilemodule:The
doraise=Truewill raise an exception and return with a nonzero exit code that you can easily test in your pre-commit hook.