| |
| """Create/update a Hugging Face dataset repository from this directory.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import re |
| import subprocess |
| import sys |
| from pathlib import Path |
|
|
|
|
| ROOT = Path(__file__).resolve().parents[1] |
|
|
|
|
| def public_release_ready() -> list[str]: |
| problems: list[str] = [] |
| readme_path = ROOT / "README.md" |
| readme = readme_path.read_text(encoding="utf-8") if readme_path.exists() else "" |
| yaml_match = re.match(r"^---\s*\n(.*?)\n---", readme, flags=re.DOTALL) |
| yaml_text = yaml_match.group(1) if yaml_match else "" |
| if not re.search(r"^license:\s*\S+", yaml_text, flags=re.MULTILINE): |
| problems.append("README.md YAML has no license field") |
| if not (ROOT / "LICENSE").is_file(): |
| problems.append("LICENSE file is missing") |
| pending_markers = ["License pending", "Citation pending"] |
| for marker in pending_markers: |
| if marker.lower() in readme.lower(): |
| problems.append(f"README.md still contains: {marker}") |
| return problems |
|
|
|
|
| def main() -> int: |
| parser = argparse.ArgumentParser(description=__doc__) |
| parser.add_argument("--repo-id", required=True, help="Hugging Face repo ID, for example org/name.") |
| parser.add_argument( |
| "--public", |
| action="store_true", |
| help="Create/update a public repo. Default is private.", |
| ) |
| parser.add_argument( |
| "--skip-validation", |
| action="store_true", |
| help="Skip the local structural validator.", |
| ) |
| args = parser.parse_args() |
|
|
| if not args.skip_validation: |
| result = subprocess.run([sys.executable, str(ROOT / "scripts" / "validate_dataset.py")]) |
| if result.returncode != 0: |
| return result.returncode |
|
|
| if args.public: |
| problems = public_release_ready() |
| if problems: |
| print("Public upload blocked:", file=sys.stderr) |
| for problem in problems: |
| print(f"- {problem}", file=sys.stderr) |
| return 2 |
|
|
| try: |
| from huggingface_hub import HfApi |
| except ImportError: |
| print("Install the client first: pip install -U huggingface_hub", file=sys.stderr) |
| return 3 |
|
|
| api = HfApi() |
| api.create_repo( |
| repo_id=args.repo_id, |
| repo_type="dataset", |
| private=not args.public, |
| exist_ok=True, |
| ) |
| api.upload_folder( |
| folder_path=str(ROOT), |
| repo_id=args.repo_id, |
| repo_type="dataset", |
| ignore_patterns=[".git/*", "**/__pycache__/*", "*.pyc"], |
| commit_message="Upload MVOT dataset v1.0.0", |
| ) |
| visibility = "public" if args.public else "private" |
| print(f"Uploaded {ROOT} to https://huggingface.co/datasets/{args.repo_id} ({visibility})") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|