File size: 2,019 Bytes
edd15df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
"""Plan a dataset upload by default; actual publication requires --upload."""
import argparse
from pathlib import Path
import re
import shlex
import shutil
import subprocess
import sys

ROOT = Path(__file__).resolve().parents[1]

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--repo-id", required=True)
    parser.add_argument("--upload", action="store_true", help="Perform the remote dataset upload")
    args = parser.parse_args()
    if not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]*", args.repo_id):
        parser.error("Expected a repository identifier in namespace/name form.")
    cmd = ["hf", "upload", args.repo_id, str(ROOT), ".", "--repo-type", "dataset"]
    print("Destination:", args.repo_id, "(dataset)", flush=True)
    print("Release root:", ROOT, flush=True)
    if not args.upload:
        print("DRY RUN — no remote requests or authentication checks performed.")
        print(shlex.join(cmd))
        return
    cli = shutil.which("hf")
    if not cli:
        parser.error("hf CLI not found. Install huggingface_hub and authenticate locally first.")
    check = subprocess.run([sys.executable, "-B", str(ROOT / "tools" / "validate_release.py")])
    if check.returncode:
        raise SystemExit(check.returncode)
    help_result = subprocess.run([cli, "upload", "--help"], text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    if help_result.returncode:
        parser.error("Could not inspect hf upload --help.")
    if "--repo-type" in help_result.stdout:
        flag = "--repo-type"
    elif "--type" in help_result.stdout:
        flag = "--type"
    else:
        parser.error("This hf CLI exposes no recognized dataset-type flag.")
    cmd = [cli, "upload", args.repo_id, str(ROOT), ".", flag, "dataset"]
    print("Uploading validated release contents to the specified dataset repository.", flush=True)
    raise SystemExit(subprocess.run(cmd).returncode)

if __name__ == "__main__":
    main()