| |
| """Offline entrypoint for studies/ (no make, no pip, no network). |
| |
| Usage: |
| python3 run.py list |
| python3 run.py test |
| python3 run.py check |
| python3 run.py derive [model] |
| python3 run.py validate [model] |
| """ |
| from __future__ import annotations |
|
|
| import json |
| import subprocess |
| import sys |
| from pathlib import Path |
|
|
| STUDIES = Path(__file__).resolve().parent |
| MODELS = sorted( |
| p.name |
| for p in (STUDIES / "models").iterdir() |
| if p.is_dir() and (p / "Makefile").exists() |
| ) |
|
|
|
|
| def run_py(script: Path, cwd: Path) -> int: |
| return subprocess.call([sys.executable, str(script)], cwd=str(cwd)) |
|
|
|
|
| def cmd_list() -> int: |
| status = STUDIES / "derived" / "STATUS.json" |
| if not status.exists(): |
| print("no STATUS.json — run: python3 run.py test") |
| return 1 |
| data = json.loads(status.read_text()) |
| print(f"{'ID':12} {'NAME':14} {'STATUS':28} {'TOTAL':8} ACTIVE") |
| print("-" * 78) |
| for m in data.get("models") or []: |
| active = m.get("active_params") |
| if active is None: |
| active = "undisclosed" |
| print( |
| f"{m['model_id']:12} {str(m.get('display_name', ''))[:14]:14} " |
| f"{str(m.get('status', ''))[:28]:28} {str(m.get('total_params') or '—'):8} {active}" |
| ) |
| return 0 |
|
|
|
|
| def models_arg(argv: list[str]) -> list[str]: |
| if argv: |
| return argv |
| return MODELS |
|
|
|
|
| def cmd_derive(names: list[str]) -> int: |
| rc = 0 |
| for m in names: |
| print(f"==> derive {m}") |
| r = run_py(STUDIES / "models" / m / "scripts" / "generate_derived.py", STUDIES / "models" / m) |
| rc = rc or r |
| return rc |
|
|
|
|
| def cmd_validate(names: list[str]) -> int: |
| rc = 0 |
| for m in names: |
| print(f"==> validate {m}") |
| r = run_py(STUDIES / "models" / m / "scripts" / "validate.py", STUDIES / "models" / m) |
| rc = rc or r |
| return rc |
|
|
|
|
| def cmd_dashboard() -> int: |
| print("==> dashboard") |
| return run_py(STUDIES / "shared" / "scripts" / "build_dashboard.py", STUDIES) |
|
|
|
|
| def cmd_packages() -> int: |
| return run_py(STUDIES / "shared" / "scripts" / "check_packages.py", STUDIES) |
|
|
|
|
| def cmd_test(names: list[str]) -> int: |
| rc = cmd_validate(names) |
| rc = cmd_dashboard() or rc |
| rc = cmd_packages() or rc |
| if rc == 0: |
| print(f"✓ test passed: {' '.join(names)}") |
| return rc |
|
|
|
|
| def cmd_check(names: list[str]) -> int: |
| rc = cmd_derive(names) |
| rc = cmd_validate(names) or rc |
| rc = cmd_dashboard() or rc |
| rc = cmd_packages() or rc |
| if rc == 0: |
| print(f"✓ check passed: {' '.join(names)}") |
| return rc |
|
|
|
|
| def main(argv: list[str]) -> int: |
| if not argv or argv[0] in ("-h", "--help", "help"): |
| print(__doc__) |
| print("models:", ", ".join(MODELS)) |
| return 0 |
| cmd, *rest = argv |
| if cmd == "list": |
| return cmd_list() |
| if cmd == "derive": |
| return cmd_derive(models_arg(rest)) |
| if cmd == "validate": |
| return cmd_validate(models_arg(rest)) |
| if cmd == "dashboard": |
| return cmd_dashboard() |
| if cmd == "test": |
| return cmd_test(models_arg(rest)) |
| if cmd == "check": |
| return cmd_check(models_arg(rest)) |
| print(f"unknown command: {cmd}", file=sys.stderr) |
| return 2 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main(sys.argv[1:])) |
|
|