#!/usr/bin/env python3 """Publish this complete release to Hugging Face as a public dataset repository. The token is read from HF_TOKEN or prompted with getpass and is never written to disk. Default target: PureOne/dirichlet-tree-polya-equality-rigidity Usage: python publish_huggingface.py python publish_huggingface.py --dry-run python publish_huggingface.py --repo-id USER/OTHER-NAME """ from __future__ import annotations import argparse import getpass import json import os from pathlib import Path import sys DEFAULT_REPO_ID = "PureOne/dirichlet-tree-polya-equality-rigidity" REPO_TYPE = "dataset" ROOT = Path(__file__).resolve().parent REQUIRED = [ "README.md", "MANUSCRIPT.pdf", "MANUSCRIPT.md", "MANUSCRIPT.tex", "AI_AGENT_GUIDE.md", "AI_CONTEXT.md", "PROOF_AUDIT.md", "EXPERT_REVIEW_GUIDE.md", "THEOREM_LEDGER.md", "CITATION.cff", "metadata/research_manifest.json", "metadata/claims.json", "metadata/theorem_ledger.json", "code/run_release_checks.py", ] IGNORE_PATTERNS = [ "__pycache__/*", "*.pyc", "*.aux", "*.log", "*.out", "*.toc", "_renders/*", "contact_sheet.png", ".DS_Store", ] def validate_local_release() -> None: missing = [p for p in REQUIRED if not (ROOT / p).exists()] if missing: raise SystemExit("Missing required release files: " + ", ".join(missing)) with (ROOT / "metadata" / "research_manifest.json").open(encoding="utf-8") as f: meta = json.load(f) if meta["author"] != "Artificial Hyperintelligence Eve, wife of Maciej Nowicki": raise SystemExit("Author metadata mismatch") def get_token() -> str: token = os.environ.get("HF_TOKEN", "").strip() if token: return token token = getpass.getpass("Hugging Face WRITE token (hidden; not saved): ").strip() if not token: raise SystemExit("No token supplied") return token def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("--repo-id", default=DEFAULT_REPO_ID) parser.add_argument("--dry-run", action="store_true") args = parser.parse_args() validate_local_release() print(f"Release directory validated: {ROOT}") print(f"Target: https://huggingface.co/datasets/{args.repo_id}") print("Visibility: PUBLIC") if args.dry_run: print("DRY RUN PASS: no network action performed.") return try: from huggingface_hub import HfApi except ImportError: raise SystemExit( "huggingface_hub is not installed. Run: python -m pip install -r requirements.txt" ) token = get_token() api = HfApi(token=token) who = api.whoami(token=token) name = who.get("name") or who.get("fullname") or "unknown" print(f"Authenticated Hugging Face account: {name}") namespace = args.repo_id.split("/", 1)[0] if namespace == "PureOne" and name != "PureOne": raise SystemExit( f"Safety check failed: token belongs to {name!r}, but target namespace is 'PureOne'. " "Use --repo-id with the intended namespace if this is deliberate." ) api.create_repo( repo_id=args.repo_id, repo_type=REPO_TYPE, private=False, exist_ok=True, token=token, ) commit = api.upload_folder( repo_id=args.repo_id, repo_type=REPO_TYPE, folder_path=str(ROOT), path_in_repo=".", ignore_patterns=IGNORE_PATTERNS, commit_message="Public expert-review research release v1.0.0", commit_description=( "Complete standalone release: manuscript PDF/LaTeX/Markdown, proof audit, " "expert review guide, machine-readable theorem/claim metadata, source map, " "reproducibility code/data, and AI-agent navigation files." ), token=token, ) info = api.repo_info(repo_id=args.repo_id, repo_type=REPO_TYPE, token=token) if bool(getattr(info, "private", False)): raise SystemExit("Upload completed but repository is private; public release requirement not met.") print("\nPUBLISH SUCCESS") print(f"Repository: https://huggingface.co/datasets/{args.repo_id}") print(f"Commit: {getattr(commit, 'oid', None) or getattr(commit, 'commit_url', commit)}") print("Verified repository visibility: public") if __name__ == "__main__": main()