File size: 1,589 Bytes
ea1b5d0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | """Create a portable build-context ZIP with explicit include/exclude rules."""
import hashlib
import json
import zipfile
from pathlib import Path
root=Path(__file__).resolve().parents[1];dest=root/'artifacts';dest.mkdir(exist_ok=True)
archive=dest/'snf-five-models-cu128-build.zip'
paths=[root/'Dockerfile',root/'.dockerignore',root/'PROJECT_OVERVIEW.md',root/'PAPER_OUTLINE.md']
paths.extend((root/'docs').glob('*.md'))
paths.extend((root/'docs/figures').glob('*.png'))
for folder in ('packaging','vendor','snf','experiments','suite'):
for path in (root/folder).rglob('*'):
if not path.is_file() or any(p in path.parts for p in ('__pycache__','.git','checkpoints','wandb','upstream_inspect')) or path.suffix.lower() in ('.pyc','.mp4','.gif'):continue
paths.append(path)
manifest={}
with zipfile.ZipFile(archive,'w',compression=zipfile.ZIP_DEFLATED,compresslevel=6) as z:
for path in sorted(paths):
relative='snf-five-models/'+path.relative_to(root).as_posix();z.write(path,relative)
manifest[relative]=hashlib.sha256(path.read_bytes()).hexdigest()
digest=hashlib.sha256(archive.read_bytes()).hexdigest()
(dest/'snf-five-models-cu128-build.zip.sha256').write_text(digest+' '+archive.name+'\n')
(dest/'bundle-manifest.json').write_text(json.dumps(dict(archive=archive.name,sha256=digest,files=manifest),indent=2))
with zipfile.ZipFile(archive) as z:
if z.testzip() is not None:raise RuntimeError('ZIP integrity failure')
print(json.dumps(dict(archive=str(archive),files=len(paths),size_mib=archive.stat().st_size/2**20,sha256=digest),indent=2))
|