-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.py
More file actions
51 lines (40 loc) · 1.32 KB
/
check.py
File metadata and controls
51 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
"""Run all code quality checks."""
import subprocess
import sys
def run(cmd: list[str], name: str) -> bool:
"""Run a command and return success status."""
print(f"\n{'=' * 60}")
print(f"Running: {name}")
print(f"{'=' * 60}")
result = subprocess.run(cmd, check=False)
if result.returncode != 0:
print(f"FAILED: {name}")
return False
print(f"PASSED: {name}")
return True
def main() -> int:
"""Run all checks."""
fix_mode = "--fix" in sys.argv
checks = [
(["uv", "run", "ruff", "format", "." if fix_mode else "--check", "."], "Ruff Format"),
(
["uv", "run", "ruff", "check", ".", *(["--fix"] if fix_mode else [])],
"Ruff Lint",
),
(["uv", "run", "mypy", "tensors.py"], "Mypy"),
]
# Fix the format check command
if not fix_mode:
checks[0] = (["uv", "run", "ruff", "format", "--check", "."], "Ruff Format")
results = [run(cmd, name) for cmd, name in checks]
print(f"\n{'=' * 60}")
if all(results):
print("All checks passed!")
return 0
else:
failed = [name for (_, name), passed in zip(checks, results, strict=True) if not passed]
print(f"Failed checks: {', '.join(failed)}")
return 1
if __name__ == "__main__":
sys.exit(main())