| """End-to-end v2 rebuild: crop new sessions, rebuild parquets, regenerate |
| previews, refresh the README v2 gallery from previews/v2/*.png. |
| |
| Replaces the manual crop -> build -> preview -> hand-edit-README loop with one |
| command. The README block between <!-- v2-gallery-start --> and |
| <!-- v2-gallery-end --> is rewritten in alphabetical session order from the |
| on-disk previews, so adding a session is purely a matter of cropping + |
| rebuilding -- the gallery follows automatically. |
| |
| Usage: |
| uv run python scripts/v2/compile.py |
| """ |
|
|
| from __future__ import annotations |
|
|
| import importlib.util |
| from pathlib import Path |
|
|
| SCRIPT_DIR = Path(__file__).resolve().parent |
| REPO_ROOT = SCRIPT_DIR.parents[1] |
| PREVIEWS_DIR = REPO_ROOT / "previews" / "v2" |
| README = REPO_ROOT / "README.md" |
| GALLERY_START = "<!-- v2-gallery-start -->" |
| GALLERY_END = "<!-- v2-gallery-end -->" |
|
|
|
|
| def _load_module(stem: str): |
| """Load a sibling script whose filename starts with a digit.""" |
| path = SCRIPT_DIR / f"{stem}.py" |
| spec = importlib.util.spec_from_file_location(stem.replace("/", "_"), path) |
| mod = importlib.util.module_from_spec(spec) |
| spec.loader.exec_module(mod) |
| return mod |
|
|
|
|
| def _refresh_readme_gallery() -> None: |
| text = README.read_text() |
| if GALLERY_START not in text or GALLERY_END not in text: |
| raise RuntimeError( |
| f"sentinel comments not found in {README}: expected " |
| f"{GALLERY_START!r} and {GALLERY_END!r}" |
| ) |
| previews = sorted(PREVIEWS_DIR.glob("*.png")) |
| body = "\n\n".join( |
| f"#### `{p.stem}`\n" for p in previews |
| ) |
| head, _, rest = text.partition(GALLERY_START) |
| _, _, tail = rest.partition(GALLERY_END) |
| README.write_text(f"{head}{GALLERY_START}\n\n{body}\n\n{GALLERY_END}{tail}") |
| print(f"refreshed README gallery: {len(previews)} sessions") |
|
|
|
|
| def main() -> None: |
| print("== 01 crop ==") |
| _load_module("01_crop_d555").main() |
| print("\n== 02 build ==") |
| _load_module("02_build_dataset").main() |
| print("\n== 03 previews ==") |
| _load_module("03_make_previews").main() |
| print("\n== readme ==") |
| _refresh_readme_gallery() |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|