oss-ecosystem-data / code /scripts /push_code.py
saladday1's picture
code: sync from git
2471af3 verified
Raw History Blame Contribute Delete
1.26 kB
"""Upload the source to the dataset repo's code/ folder (the daily HF Job runs from there).
python scripts/push_code.py
Uploads every git-tracked file except eval/ (the hand-labelled holdout): the pipeline, the
page's source in web/ and the Space card, 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("eval/")]
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")