YEORIN-X-v4-Research / tools /make_release.py
PureOne's picture
Release YEORIN-X v4 reproducible research and engineering package
871e4fa verified
Raw History Blame Contribute Delete
1.44 kB
"""Create a source/evidence distribution with an internal SHA-256 inventory."""
import argparse,hashlib,zipfile
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('output',type=Path);a=p.parse_args()
root=Path(__file__).resolve().parents[1]
excluded={'__pycache__','.pytest_cache','build','.git','.venv'}
files=[f for f in root.rglob('*') if f.is_file() and not any(x in excluded for x in f.relative_to(root).parts)
and f.suffix not in {'.pyc','.pyo'} and f.name!='SHA256SUMS.txt' and f.resolve()!=a.output.resolve()]
files=sorted(files,key=lambda f:f.relative_to(root).as_posix())
def digest(f):
h=hashlib.sha256()
with f.open('rb') as stream:
for b in iter(lambda:stream.read(1<<20),b''):h.update(b)
return h.hexdigest()
manifest=root/'SHA256SUMS.txt'
manifest.write_text(''.join(digest(f)+' '+f.relative_to(root).as_posix()+'\n' for f in files))
files.append(manifest);a.output.parent.mkdir(parents=True,exist_ok=True)
with zipfile.ZipFile(a.output,'w',compression=zipfile.ZIP_DEFLATED,compresslevel=7) as z:
for f in files:
name=root.name+'/'+f.relative_to(root).as_posix()
info=zipfile.ZipInfo(name,date_time=(2026,10,10,0,0,0));info.compress_type=zipfile.ZIP_DEFLATED
info.external_attr=(0o100644<<16)
z.writestr(info,f.read_bytes(),compress_type=zipfile.ZIP_DEFLATED,compresslevel=7)
print('Archive',a.output,'files',len(files),'payload hashes',len(files)-1,'bytes',a.output.stat().st_size)