Jump to content

The Principia Machina/TPC-PY/crosspy.py

From The Invariance Itself
Revision as of 15:43, 27 September 2026 by BFP Rauch (talk | contribs) (TPC-PY source crosspy.py (0.1.0), SHA-256 29a46269c301bf24; conformed TPS 0.3.0; PROPOSED, not declared (CO-8))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
"""crosspy 0.1.0: runs a module's run_case over the case file of its
differential and prints the SHA-256 of the output list, so the same command
under Python 3.10, 3.11, 3.12 and 3.13 proves the Python residence
byte-identical across interpreters on the differential's inputs.
Usage: python3.X crosspy.py <module dir> <module name> [case file].
The case file is the one diff_<name>.py kept where the environment variable
TPC_DIFF_CASES named it (the harnesses write no file in the tree since
2026-09-27, GEN-PATHS); without the argument, TPC_DIFF_CASES, and without
that, diff_cases.json in the module dir, as the harnesses left it before."""
import hashlib, importlib, json, os, sys
d = os.path.abspath(sys.argv[1])
sys.path.insert(0, d)
m = importlib.import_module(sys.argv[2])
cf = (sys.argv[3] if len(sys.argv) > 3 else
      os.environ.get("TPC_DIFF_CASES") or os.path.join(d, "diff_cases.json"))
cases = json.load(open(cf, encoding="utf-8"))
if sys.argv[2] == "tpc_cluster":
    out = [m.run_case(c) for c in cases]
else:
    out = [m.run_case(c["fn"], c["args"]) for c in cases]
h = hashlib.sha256(json.dumps(out, ensure_ascii=False).encode("utf-8")).hexdigest()
print("%s python %s cases %d sha256 %s" % (sys.argv[2], sys.version.split()[0], len(out), h[:16]))