"""Explicit upload helper; never called by build or validation.""" from pathlib import Path import argparse import json from huggingface_hub import HfApi from huggingface_hub.errors import RepositoryNotFoundError from verify import verify ROOT = Path(__file__).resolve().parents[1] def main(): p = argparse.ArgumentParser(description=__doc__) p.add_argument('--repo-id', required=True, help='HF namespace/dataset-name') p.add_argument('--public', action='store_true', help='Publish publicly; default is private.') args = p.parse_args() assert len(args.repo_id.split('/')) == 2 and all(args.repo_id.split('/')), 'Use namespace/name' verify(ROOT) api = HfApi() # Resolve the destination first: never delete stale remote files or change access. try: info = api.repo_info(args.repo_id, repo_type='dataset') except RepositoryNotFoundError: api.create_repo(args.repo_id, repo_type='dataset', private=not args.public) else: assert info.private == (not args.public), 'Existing repository visibility differs; review it separately.' remote = set(api.list_repo_files(args.repo_id, repo_type='dataset')) local = {x['path'] for x in json.loads((ROOT / 'metadata/file_manifest.json').read_text())['files']} | {'metadata/file_manifest.json'} extras = remote - local assert not extras, f'Remote contains unrelated/stale files: {sorted(extras)}' result = api.upload_folder(repo_id=args.repo_id, repo_type='dataset', folder_path=str(ROOT), ignore_patterns=['.git/**', '.cache/**', '.venv/**', '**/__pycache__/**', '**/*.pyc', '.DS_Store'], commit_message='Publish verified μ-Bench release dataset snapshot') print(result) if __name__ == '__main__': main()