_runner.py
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
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SCRIPTS_DIR = ROOT / "scripts"
if str(SCRIPTS_DIR) not in sys.path:
sys.path.insert(0, str(SCRIPTS_DIR))
def run_script(path: str) -> int:
script_path = ROOT / path
module_name = f"_workflow_{script_path.stem}"
spec = importlib.util.spec_from_file_location(module_name, script_path)
if spec is None or spec.loader is None:
raise RuntimeError(f"Cannot load script: {script_path}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if not hasattr(module, "main"):
raise RuntimeError(f"Script has no main(): {script_path}")
result = module.main()
return int(result or 0)
def run_scripts(paths: list[str]) -> int:
for path in paths:
print(f"\n==> Running {path}")
code = run_script(path)
if code != 0:
print(f"Stopped at {path} with exit code {code}")
return code
return 0
def print_artifacts(paths: list[str]) -> None:
existing = [ROOT / path for path in paths if (ROOT / path).exists()]
if not existing:
print("\nGenerated files: none")
return
print("\nGenerated files:")
for path in existing:
print(f"- {path.relative_to(ROOT)}")