File size: 2,161 Bytes
3b3b2bd | 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 27 28 29 | """Create an allowlisted source release. Does not publish or include private memory."""
from pathlib import Path
import argparse,hashlib,json,zipfile
ROOT=Path(__file__).resolve().parents[1]
ROOT_FILES=['CHANGELOG.md','README.md','MODEL_CARD.md','MODEL_CARD_PREVIEW.html','LICENSE','NOTICE.md',
'config.json','rankers.ugr','model.safetensors','evidence.ugr','evidence.safetensors','evidence.json','sensemap.json','pyproject.toml','requirements.txt','Dockerfile','.dockerignore','.gitignore','.gitattributes']
DIRECTORIES=['phillnet_recall','native','scripts','tests','examples','docs','assets','reports','provenance','deploy','space','.github']
IGNORE={'__pycache__','.pytest_cache','build','dist'}
FORBIDDEN=('.sqlite','.sqlite3','.db','.env','.key','.pem','.sqlite3-wal','.sqlite3-shm','.db-wal','.db-shm')
def main():
p=argparse.ArgumentParser();p.add_argument('--output',default=str(ROOT.parent/'PhillNet-Recall-1.2.0.zip'));a=p.parse_args()
files=[ROOT/n for n in ROOT_FILES]
for d in DIRECTORIES:
for path in (ROOT/d).rglob('*'):
if path.is_file() and path.suffix not in ('.so','.dll','.dylib') and not any(part in IGNORE for part in path.parts) and path.suffix not in ('.pyc','.pyo'):
if path.is_symlink() or path.name.lower().endswith(FORBIDDEN):raise ValueError(f'refusing private or linked file: {path}')
files.append(path)
files=sorted(set(files))
manifest={'schema':'phillnet.release.v1','name':'PhillNet Recall','version':'1.2.0','intended_repository':'ayjays132/PhillNet-Recall',
'publication_performed':False,'files':[{'path':str(p.relative_to(ROOT)),'bytes':p.stat().st_size,'sha256':hashlib.sha256(p.read_bytes()).hexdigest()} for p in files]}
(ROOT/'release_manifest.json').write_text(json.dumps(manifest,indent=2)+'\n')
files.append(ROOT/'release_manifest.json')
out=Path(a.output)
with zipfile.ZipFile(out,'w',zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for f in files:z.write(f,arcname='PhillNet-Recall/'+str(f.relative_to(ROOT)))
print(json.dumps({'archive':str(out),'files':len(files),'bytes':out.stat().st_size,'sha256':hashlib.sha256(out.read_bytes()).hexdigest()},indent=2))
if __name__=='__main__':main()
|