omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tools / adapters / python-import
| 1 | #!/usr/bin/env python3 |
| 2 | """Transparent host dispatch; parsing and hashing run in seeded native Omega (#627). |
| 3 | Usage: python-import < computation.py > unit.upper""" |
| 4 | from pathlib import Path |
| 5 | import hashlib,json,os,sys |
| 6 | root=Path(__file__).resolve().parents[2] |
| 7 | INPUTS={'src/source-aware/vendor/sha256.om','src/adapters/python-u64-import.om'} |
| 8 | if len(sys.argv)!=1: |
| 9 | print('PY_IMPORT_BAD_COMMAND: use stdin source; no arguments',file=sys.stderr);raise SystemExit(64) |
| 10 | try: |
| 11 | build=root/'build/L627/import';m=json.loads((build/'build.json').read_text());exe=build/'python-import' |
| 12 | if m['compiler_sha256']!='191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9':raise ValueError('compiler identity') |
| 13 | if set(m['inputs'])!=INPUTS:raise ValueError('source closure') |
| 14 | for rel,digest in m['inputs'].items(): |
| 15 | if hashlib.sha256((root/rel).read_bytes()).hexdigest()!=digest:raise ValueError('changed source') |
| 16 | if hashlib.sha256(exe.read_bytes()).hexdigest()!=m['binary_sha256']:raise ValueError('changed artifact') |
| 17 | except (OSError,ValueError,KeyError) as exc: |
| 18 | print('PY_IMPORT_STALE_OR_MISSING_BUILD: '+str(exc),file=sys.stderr);raise SystemExit(78) |
| 19 | os.execv(exe,[str(exe)]) |