"""Build a deterministic source/research ZIP from the verified release manifest.""" import argparse from pathlib import Path import zipfile from celestis_rl.release import verify_manifest,MANIFEST def main(): p=argparse.ArgumentParser(description=__doc__) p.add_argument("--root",default=str(Path(__file__).resolve().parents[1])) p.add_argument("--output",required=True) args=p.parse_args();root=Path(args.root).resolve();out=Path(args.output).resolve() if root==out or root in out.parents: raise ValueError("write archives outside the source tree to avoid including the archive in itself") m=verify_manifest(root);out.parent.mkdir(parents=True,exist_ok=True) with zipfile.ZipFile(out,'w',compression=zipfile.ZIP_DEFLATED,compresslevel=9) as z: for rel in sorted([*m['files'],MANIFEST]): info=zipfile.ZipInfo(f"{root.name}/{rel}",date_time=(2026,9,21,0,0,0)) info.compress_type=zipfile.ZIP_DEFLATED info.external_attr=((0o755 if rel.endswith('.sh') else 0o644)&0xFFFF)<<16 z.writestr(info,(root/rel).read_bytes(),compresslevel=9) with zipfile.ZipFile(out) as z: if z.testzip() is not None: raise ValueError('ZIP CRC verification failed') print(f"Created {out.name}: {len(m['files'])+1} files, {out.stat().st_size} bytes") if __name__=='__main__':main()