okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
be32c7f3f
main
1"""Write the snapshot of every (machine class, model set) as golden/<machine>/<set>.json, or print a table. 2 3python -m tests.snapshot.generate --out tests/snapshot/golden (rewrite the golden files; the only way they change) 4python -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 : 21return {"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 : 25return json .dumps (data ,indent = 1 ,sort_keys = False ,ensure_ascii = False )+ "\n" 26 27 28def main (argv = None )-> int : 29ap = argparse .ArgumentParser () 30ap .add_argument ("--out" ,default = str (GOLDEN )) 31ap .add_argument ("--machine" ,action = "append" ) 32ap .add_argument ("--set" ,action = "append" ) 33a = ap .parse_args (argv ) 34out = Path (a .out ) 35for m in MACHINES : 36if a .machine and m .key not in a .machine : 37continue 38for s in MODEL_SETS : 39if a .set and s .key not in a .set : 40continue 41path = out / m .key / f" { s . key } .json" 42path .parent .mkdir (parents = True ,exist_ok = True ) 43path .write_text (dump (cell (m .key ,s .key )),encoding = "utf-8" ,newline = "\n" ) 44"wrote" ,path ,flush = True ) 45return 0 46 47 48if __name__ == "__main__" : 49sys .exit (main ())