| |
| """Sync root README status section from derived/STATUS.json.""" |
| from __future__ import annotations |
|
|
| import json |
| import re |
| import sys |
| from pathlib import Path |
|
|
| ROOT = Path(__file__).resolve().parents[2] |
| README = ROOT / "README.md" |
| STATUS = ROOT / "derived" / "STATUS.json" |
|
|
| START = "<!-- status:start -->" |
| END = "<!-- status:end -->" |
|
|
|
|
| def build_block(status: dict) -> str: |
| |
| lines = [START, ""] |
| for m in status.get("models") or []: |
| active = m.get("active_params") |
| if active is None: |
| active = "undisclosed" |
| total = m.get("total_params") or "?" |
| lines.append( |
| f"- [`{m['model_id']}`](models/{m['model_id']}/) — {m['display_name']}: " |
| f"{total} / {active}, status `{m['status']}`" |
| ) |
| lines += [ |
| "", |
| f"[full table](derived/DASHBOARD.md) · {status.get('generated_at_utc', '')}", |
| "", |
| END, |
| ] |
| return "\n".join(lines) |
|
|
|
|
| def main() -> int: |
| if not STATUS.exists(): |
| print("missing derived/STATUS.json — run make dashboard first", file=sys.stderr) |
| return 1 |
| if not README.exists(): |
| return 0 |
| text = README.read_text() |
| |
| if START not in text and "## Status" not in text: |
| print("README has no status anchors — skip") |
| return 0 |
| status = json.loads(STATUS.read_text()) |
| block = build_block(status) |
| if START in text and END in text: |
| new = re.sub( |
| re.escape(START) + r".*?" + re.escape(END), |
| block, |
| text, |
| count=1, |
| flags=re.S, |
| ) |
| else: |
| |
| if "## Status" in text: |
| new = re.sub( |
| r"(## Status\n)", |
| r"\1\n" + block + "\n", |
| text, |
| count=1, |
| ) |
| else: |
| new = text.rstrip() + "\n\n## Status\n\n" + block + "\n" |
|
|
| if new != text: |
| README.write_text(new) |
| print("✓ README status section synced") |
| else: |
| print("README status already current") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|