File size: 2,997 Bytes
f68295a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0397a1e
f68295a
 
 
 
 
 
 
 
 
 
 
 
 
0397a1e
f68295a
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""Crée (si besoin) le dépôt Dataset PRIVÉ et y pousse README + données validées.

Par défaut : simulation (dry-run). Ajouter --yes pour agir.
Le jeton est lu dans HF_TOKEN (droits « write »), jamais passé en argument.

    export HF_TOKEN=hf_xxx
    python scripts/create_and_push.py                       # simulation
    python scripts/create_and_push.py --yes                 # crée le dépôt vide + README
    python scripts/create_and_push.py --yes --data data/    # + pousse les JSONL validés
"""
from __future__ import annotations

import argparse
import os
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
DEFAULT_REPO = "RDS777/sky-trajectories"


def main(argv: list[str] | None = None) -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--repo", default=DEFAULT_REPO)
    ap.add_argument("--data", type=Path, default=None, help="dossier de JSONL à pousser (validés d'abord)")
    ap.add_argument("--hidden-dir", type=Path, default=None)
    ap.add_argument("--yes", action="store_true")
    a = ap.parse_args(argv)

    files = sorted(a.data.glob("*.jsonl")) if a.data else []
    if files:
        cmd = [sys.executable, str(ROOT / "scripts" / "validate.py"), *map(str, files)]
        if a.hidden_dir:
            cmd += ["--hidden-dir", str(a.hidden_dir)]
        if subprocess.run(cmd, stdout=subprocess.DEVNULL).returncode != 0:
            print("Validation échouée : rien n'est poussé. Lancez validate.py pour le détail.", file=sys.stderr)
            return 1
        if not a.hidden_dir:
            print("AVERTISSEMENT : fuite de tests cachés non contrôlée (pas de --hidden-dir).", file=sys.stderr)

    print(f"Dépôt cible : datasets/{a.repo} (privé)")
    print(f"Carte du dataset : {ROOT / 'DATASET_CARD.md'} (publiée comme README.md du dépôt Dataset)")
    print(f"JSONL à pousser : {[f.name for f in files] or 'aucun (dépôt vide + README)'}")
    if not a.yes:
        print("Simulation seulement. Relancez avec --yes pour agir.")
        return 0

    token = os.environ.get("HF_TOKEN")
    if not token:
        print("HF_TOKEN absent de l'environnement.", file=sys.stderr)
        return 2
    from huggingface_hub import HfApi

    api = HfApi(token=token)
    api.create_repo(a.repo, repo_type="dataset", private=True, exist_ok=True)
    api.upload_file(path_or_fileobj=str(ROOT / "DATASET_CARD.md"), path_in_repo="README.md",
                    repo_id=a.repo, repo_type="dataset", commit_message="Carte du dataset")
    for f in files:
        api.upload_file(path_or_fileobj=str(f), path_in_repo=f"data/{f.name}", repo_id=a.repo,
                        repo_type="dataset", commit_message=f"Ajout {f.name}")
    info = api.repo_info(a.repo, repo_type="dataset")
    print(f"OK — https://huggingface.co/datasets/{a.repo} (private={info.private})")
    return 0 if info.private else 3


if __name__ == "__main__":
    raise SystemExit(main())