Add tooling to detect Python2 syntax errors

This commit is contained in:
adisbladis 2022-01-12 18:39:52 +13:00
parent 8078110a7f
commit b8d3545eba
2 changed files with 17 additions and 0 deletions

View file

@ -14,6 +14,7 @@ pkgs.mkShell {
buildInputs = [
tools.env
tools.py2-astparse
tools.flamegraph
tools.release
pkgs.nixpkgs-fmt

View file

@ -77,4 +77,20 @@ in
projectDir = ./.;
};
py2-astparse = pkgs.writeScriptBin "py2-astparse" ''
#!${pkgs.python2.interpreter}
# Used as a smoke test for Python2 compatibility in Python files
import sys
import ast
if __name__ == "__main__":
with open(sys.argv[1]) as f:
try:
ast.parse(f.read())
except Exception as e:
sys.stderr.write("Error parsing '{}':\n".format(sys.argv[1]))
sys.stderr.flush()
raise
'';
}