"""Package current source plus simulation adapters into a digest-addressed archive.""" import argparse import ast import hashlib import json import tarfile import runpy import urllib.request from pathlib import Path root = Path(__file__).resolve().parents[2] parser = argparse.ArgumentParser() parser.add_argument("--output", type=Path, required=True) args = parser.parse_args() args.output.mkdir(parents=True, exist_ok=True) files = sorted( p for folder in (root / "src", root / "simulation/ai-polygon", root / "simulation/urban-mapping") for p in folder.rglob("*") if p.is_file() and not p.is_symlink() and "__pycache__" not in p.parts and ".build" not in p.parts ) # Only the declared Gaussian pipeline closure ships; historical review scripts # and private qualification directories are not part of the worker artifact. from infrastructure_pipeline import definition_files module = root / "simulation/urban-plan-research" _, urban_files = definition_files(module) files.extend(module / relative for relative in urban_files) # Pinned runtime wheels are artifact assets, never a global pip installation. pins = runpy.run_path(str(module / "catalog_pass/catalog_dependency_pins.py"))["PINS"] cache = args.output / "urban-dependencies" cache.mkdir(exist_ok=True) assets = {} for pin in pins: path = cache / pin["file"] if not path.exists() or hashlib.sha256(path.read_bytes()).hexdigest() != pin["sha256"]: with urllib.request.urlopen(pin["url"], timeout=120) as response: raw = response.read(32 * 1024**2 + 1) if len(raw) > 32 * 1024**2 or hashlib.sha256(raw).hexdigest() != pin["sha256"]: raise ValueError("Pinned urban runtime dependency changed") path.write_bytes(raw) assets["simulation/urban-plan-research/pipeline/vendor/" + pin["file"]] = path files.extend((root / "apps/control-station/public/vendor/playcanvas/draco/1.5.7").glob("*")) # The canonical Rover 006 asset is shared with PlayCanvas, not a second model. for profile in (root / "simulation/ai-polygon/robots").glob("*.json"): asset = root / json.loads(profile.read_text())["visual"]["source"] if asset not in files: files.append(asset) # Reject a broken Python artifact before staging or touching the running worker. for source in files: if source.suffix == ".py": ast.parse(source.read_bytes(), filename=str(source)) manifest = { p.relative_to(root).as_posix(): hashlib.sha256(p.read_bytes()).hexdigest() for p in files } manifest.update({name: hashlib.sha256(p.read_bytes()).hexdigest() for name, p in assets.items()}) encoded = json.dumps(manifest, sort_keys=True, indent=2).encode() identity = hashlib.sha256(encoded).hexdigest() path = args.output / ("ai-polygon-" + identity[:16] + ".tgz") with tarfile.open(path, "w:gz") as archive: for p in files: archive.add(p, arcname=p.relative_to(root).as_posix(), recursive=False) for name, asset in assets.items(): archive.add(asset, arcname=name, recursive=False) manifest_path = path.with_suffix(".manifest.json") manifest_path.write_bytes(encoded) print( json.dumps( { "bundle": str(path), "identity": identity, "sha256": hashlib.sha256(path.read_bytes()).hexdigest(), "files": len(files), } ) )