| """Publish the user-authorized staged release to the Ethosoft organization.""" |
| from pathlib import Path |
| import argparse,hashlib,json,os,sys,zipfile |
| os.environ['HF_HUB_DISABLE_PROGRESS_BARS']='1' |
| from huggingface_hub import HfApi |
| ROOT=Path(__file__).resolve().parents[1] |
| REPO='Ethosoft/RefSeg-CA' |
|
|
| def main(): |
| ap=argparse.ArgumentParser();ap.add_argument('--update-documents',action='store_true') |
| ap.add_argument('--publish-source',action='store_true');ap.add_argument('--release-tag');a=ap.parse_args() |
| source=ROOT/'release_public' |
| manifest=json.loads((source/'DATA_MANIFEST.json').read_text()) |
| for name,meta in manifest['files'].items(): |
| p=source/name;assert p.stat().st_size==meta['bytes'] |
| assert hashlib.sha256(p.read_bytes()).hexdigest()==meta['sha256'],name |
| with zipfile.ZipFile(source/'release/RefSeg_CA_R3_Public_Source.zip') as z:assert z.testzip() is None |
| assert (source/'release/RefSeg_CA_MVA.pdf').read_bytes().startswith(b'%PDF') |
| api=HfApi();identity=api.whoami();assert identity['name']=='nmsofficial' |
| assert any(o['name']=='Ethosoft' for o in identity.get('orgs',[])) |
| print(json.dumps({'phase':'validated','repo':REPO,'files':len(manifest['files'])}),flush=True) |
| api.create_repo(REPO,repo_type='dataset',private=False,exist_ok=True) |
| kwargs={} |
| if a.update_documents:kwargs['allow_patterns']=['README.md','release/**']+(['source/**'] if a.publish_source else []) |
| commit=api.upload_folder(repo_id=REPO,repo_type='dataset',folder_path=source, |
| commit_message='R3 public code, data and manuscript' if not a.update_documents else 'Add verified public availability and human-evaluation guide',**kwargs) |
| tag=a.release_tag or ('r3-release-v1' if a.update_documents else 'r3-data-v1') |
| api.create_tag(REPO,tag=tag,repo_type='dataset',revision=commit.oid,exist_ok=True) |
| info=api.repo_info(REPO,repo_type='dataset');assert info.private is False |
| receipt=dict(status='PUBLISHED',repo_id=REPO,url='https://huggingface.co/datasets/'+REPO,commit=commit.oid,tag=tag,private=info.private, |
| files=len(api.list_repo_files(REPO,repo_type='dataset',revision=commit.oid))) |
| out=ROOT/'protocol'/('public_release_receipt.json' if a.update_documents else 'public_data_receipt.json') |
| out.write_text(json.dumps(receipt,indent=2));print(json.dumps(receipt),flush=True) |
|
|
| if __name__=='__main__': |
| try:main() |
| except Exception as e: |
| |
| print(json.dumps({'status':'FAILED','error_type':type(e).__name__,'http_status':getattr(getattr(e,'response',None),'status_code',None)}),flush=True) |
| sys.exit(1) |
|
|