okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-clean-step0' into f-clean-1abe32c7f3f

main
1.6 KiB49 linesraw
1"""Write the snapshot of every (machine class, model set) as golden/<machine>/<set>.json, or print a table.
2
3  python -m tests.snapshot.generate --out tests/snapshot/golden            (rewrite the golden files; the only way they change)
4  python -m tests.snapshot.generate --out DIR --machine nv_resident --set iq3_s
5"""
6
7from __future__ import annotations
8
9import argparse
10import json
11import sys
12from pathlib import Path
13
14from .driver import drive
15from .matrix import ENTRY_POINTS, MACHINES, MODEL_SETS
16
17GOLDEN = Path(__file__).resolve().parent / "golden"
18
19
20def cell(machine_key: str, set_key: str, entries=ENTRY_POINTS) -> dict:
21    return {"machine": machine_key, "set": set_key, "entries": {e: drive(machine_key, set_key, e) for e in entries}}
22
23
24def dump(data: dict) -> str:
25    return json.dumps(data, indent=1, sort_keys=False, ensure_ascii=False) + "\n"
26
27
28def main(argv=None) -> int:
29    ap = argparse.ArgumentParser()
30    ap.add_argument("--out", default=str(GOLDEN))
31    ap.add_argument("--machine", action="append")
32    ap.add_argument("--set", action="append")
33    a = ap.parse_args(argv)
34    out = Path(a.out)
35    for m in MACHINES:
36        if a.machine and m.key not in a.machine:
37            continue
38        for s in MODEL_SETS:
39            if a.set and s.key not in a.set:
40                continue
41            path = out / m.key / f"{s.key}.json"
42            path.parent.mkdir(parents=True, exist_ok=True)
43            path.write_text(dump(cell(m.key, s.key)), encoding="utf-8", newline="\n")
44            print("wrote", path, flush=True)
45    return 0
46
47
48if __name__ == "__main__":
49    sys.exit(main())