"""Write variability.json (draft classes of every bundle, engine/variability.py) into each protected template that lacks one, or into all with --force (2026-10-16). usage: python tools/make_variability.py [--force]""" import json import sys from pathlib import Path APP = Path(__file__).resolve().parents[1] sys.path.insert(0, str(APP)) from engine import variability # noqa: E402 force = "--force" in sys.argv root = APP / "data" / "_템플릿" for d in sorted(root.iterdir()): if d.name.startswith("_") or not (d / "params.json").exists(): continue out = d / "variability.json" if out.exists() and not force: print("keep", d.name) continue P = json.loads((d / "params.json").read_text(encoding="utf-8")) E = json.loads((d / "expected.json").read_text(encoding="utf-8")) v = variability.build(P, E) out.write_text(json.dumps(v, ensure_ascii=False, indent=1), encoding="utf-8") from collections import Counter c = Counter(s["grade"] for s in v["sections"].values() if not s["info"]) print("wrote", d.name, len(v["sections"]), "bundles", dict(c), "info", sum(s["info"] for s in v["sections"].values()))