File size: 1,212 Bytes
226b7bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Upload the pipeline code to the dataset repo's code/ folder (the daily HF Job runs from there).

    python scripts/push_code.py

Uploads every git-tracked file outside web/ and eval/, so a new module can't be forgotten.
"""
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
from huggingface_hub import CommitOperationAdd, CommitOperationDelete  # noqa: E402

from hfeco.hub import api  # noqa: E402
from hfeco.store import DATASET_REPO  # noqa: E402

files = subprocess.run(["git", "ls-files"], cwd=ROOT, capture_output=True, text=True, check=True).stdout.split()
files = [f for f in files if not f.startswith(("web/", "eval/", "space/"))]
remote = {f[len("code/"):] for f in api.list_repo_files(DATASET_REPO, repo_type="dataset") if f.startswith("code/")}
ops = [CommitOperationAdd(path_in_repo=f"code/{f}", path_or_fileobj=str(ROOT / f)) for f in files]
ops += [CommitOperationDelete(path_in_repo=f"code/{f}") for f in sorted(remote - set(files))]
api.create_commit(DATASET_REPO, ops, repo_type="dataset", commit_message="code: sync from git")
print(f"code/: {len(files)} files uploaded, {len(remote - set(files))} removed")