Coverage for additional_code_checks.py: 0%
34 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
1import ast
2import sys
3from glob import glob
6def check_ast(node: ast.AST, path: str):
7 ok = True
8 if hasattr(node, "body"):
9 for child in node.body:
10 child_ok = check_ast(child, path)
11 ok = ok and child_ok
12 else:
13 if isinstance(node, ast.Assert):
14 print(f"assert detected in line {node.lineno} of {path}")
15 ok = False
16 if isinstance(node, ast.Expr) and isinstance(node.value, ast.Call):
17 value = node.value
18 if (
19 hasattr(value, "func")
20 and hasattr(value.func, "id")
21 and value.func.id == "print"
22 ):
23 print(f"print detected in line {node.lineno} of {path}")
24 ok = False
25 return ok
28def check_modules(globpath: str):
29 paths = glob(globpath)
30 ok = True
31 for path in paths:
32 print("checking", path)
33 with open(path) as f:
34 tree = ast.parse(f.read())
35 module_ok = check_ast(tree, path)
36 ok = ok and module_ok
37 if ok:
38 sys.exit(0)
39 else:
40 sys.exit(1)
43if __name__ == "__main__":
44 globpath = sys.argv[1]
45 print("checking", globpath)
46 check_modules(globpath)