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_compile
module:
$ python -tt -c "import py_compile; py_compile.compile('test.py', doraise=True)"
The doraise=True
will raise an exception and return with a nonzero exit code that you can easily test in your pre-commit hook.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With