"""Package only intended research deliverables; no credentials, git objects or local scratch files."""
import pathlib,zipfile,json,hashlib,csv,html
root=pathlib.Path(__file__).resolve().parents[1]
# Supplemental bibliography is readable offline; the known mismatch remains flagged.
with open(root/'references/drugage_bibliography.csv') as f:refs=list(csv.DictReader(f))
body='<h1>DrugAge source-key bibliography</h1><p>Public metadata retrieved 5 September 2026. Article-level values were not fully re-extracted. Source 101039 is unresolved and explicitly flagged.</p><ol>'
for r in refs:
 text=' '.join([r['authors'],r['title'],r['journal'],r['date'],r['volume'],r['issue'],r['pages'],r['doi']])
 body+=f'<li><p><strong>Source key {r["source_key"]}.</strong> {html.escape(text)} <a href="{html.escape(r["url"])}">Source link</a></p><p>{html.escape(r["verification_note"])}</p></li>'
(root/'references/drugage_bibliography.html').write_text('<!doctype html><html lang="en"><meta charset="utf-8"><title>DrugAge source bibliography</title><body>'+body+'</ol></body></html>')
files=[]
for dirname in ['protocol','data','results','scripts','papers','references','output','release']:
 files.extend(p for p in (root/dirname).rglob('*') if p.is_file() and '__pycache__' not in p.parts and p.suffix!='.zip' and p.name!='archive-sha256.txt')
# Include frozen upstream archives, but never include the deliverable archive in itself.
files.extend((root/'data/raw').glob('*.zip'))
files.extend(root/p for p in ['README.md','requirements-verification.txt','requirements-rendering.txt'])
files=sorted(set(files))
archive=root/'release/australis-research-reproduction.zip'
with zipfile.ZipFile(archive,'w',compression=zipfile.ZIP_DEFLATED,compresslevel=9) as z:
 for p in files:z.write(p,p.relative_to(root))
sha=hashlib.sha256(archive.read_bytes()).hexdigest()
(root/'release/archive-sha256.txt').write_text(sha+'  australis-research-reproduction.zip\n')
print(json.dumps(dict(path=str(archive),bytes=archive.stat().st_size,files=len(files),sha256=sha),indent=2))
