-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci.py
More file actions
69 lines (54 loc) · 1.64 KB
/
Copy pathci.py
File metadata and controls
69 lines (54 loc) · 1.64 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
"""Local CI — runs the same checks as .github/workflows/ci.yml.
Usage:
python ci.py # run all checks
python ci.py lint # mypy + pyright only
python ci.py test # pytest only
"""
from __future__ import annotations
import subprocess
import sys
import time
STEPS: dict[str, list[list[str]]] = {
"lint": [
["mypy", "src/"],
["pyright", "src/"],
],
"test": [
["pytest", "-v"],
],
}
def run_step(cmd: list[str]) -> bool:
label = " ".join(cmd)
print(f"\n{'─' * 60}")
print(f" ▶ {label}")
print(f"{'─' * 60}")
t0 = time.perf_counter()
result = subprocess.run(cmd)
elapsed = time.perf_counter() - t0
ok = result.returncode == 0
status = "✓ PASS" if ok else "✗ FAIL"
print(f" {status} ({elapsed:.1f}s)")
return ok
def main() -> None:
subset = sys.argv[1] if len(sys.argv) > 1 else None
if subset and subset not in STEPS:
print(f"Unknown target: {subset!r}. Use: {', '.join(STEPS)}")
sys.exit(1)
groups = [subset] if subset else list(STEPS)
results: list[tuple[str, bool]] = []
t_start = time.perf_counter()
for group in groups:
for cmd in STEPS[group]:
ok = run_step(cmd)
results.append((" ".join(cmd), ok))
elapsed_total = time.perf_counter() - t_start
print(f"\n{'═' * 60}")
print(f" Results ({elapsed_total:.1f}s total):")
for label, ok in results:
print(f" {'✓' if ok else '✗'} {label}")
print(f"{'═' * 60}")
if not all(ok for _, ok in results):
sys.exit(1)
if __name__ == "__main__":
main()