-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_all.py
More file actions
102 lines (78 loc) · 2.38 KB
/
build_all.py
File metadata and controls
102 lines (78 loc) · 2.38 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""
Build All Plots
Regenerates all static and interactive visualizations from source.
"""
import sys
import subprocess
from pathlib import Path
from scripts.manifest_utils import plot_entries
def run_script(script_path: Path, plot_name: str) -> bool:
"""Run a Python script with proper working directory."""
script_name = script_path.name
src_dir = script_path.parent
try:
result = subprocess.run(
[sys.executable, script_name],
cwd=src_dir,
capture_output=True,
text=True,
timeout=120
)
if result.returncode == 0:
return True
else:
print(f" STDERR: {result.stderr[:200]}" if result.stderr else "")
return False
except subprocess.TimeoutExpired:
print(f" Timeout after 120s")
return False
except Exception as e:
print(f" Error: {e}")
return False
def build_plot(plot_dir: Path) -> tuple[int, int]:
"""Build all scripts in a plot's src/ directory."""
src_dir = plot_dir / "src"
if not src_dir.exists():
return 0, 0
scripts = sorted(src_dir.glob("*.py"))
success = 0
failed = 0
for script in scripts:
script_name = script.name
result = run_script(script, plot_dir.name)
if result:
print(f" {script_name}: OK")
success += 1
else:
print(f" {script_name}: FAIL")
failed += 1
return success, failed
def main():
print("=" * 60)
print("Building All Plots")
print("=" * 60)
root = Path(__file__).parent
total_success = 0
total_failed = 0
for entry in plot_entries(root, published_only=True):
plot_name = entry["id"]
plot_dir = root / plot_name
if not plot_dir.exists():
print(f"\n{plot_name}/: NOT FOUND")
continue
src_dir = plot_dir / "src"
if not src_dir.exists():
print(f"\n{plot_name}/: no src/ directory")
continue
print(f"\n{plot_name}/")
success, failed = build_plot(plot_dir)
total_success += success
total_failed += failed
print("\n" + "=" * 60)
print(f"Summary: {total_success} succeeded, {total_failed} failed")
print("=" * 60)
if total_failed > 0:
sys.exit(1)
if __name__ == "__main__":
main()