File size: 1,568 Bytes
2eaa456
226b7bf
 
 
2eaa456
 
 
226b7bf
2eaa456
226b7bf
 
 
 
 
 
 
 
 
 
cab6640
226b7bf
2eaa456
226b7bf
 
 
 
 
 
 
2eaa456
 
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
26
27
28
29
30
31
32
33
34
"""Build the page (web/) and upload it to the Space, leaving the daily data alone.

    python scripts/deploy_space.py

The page is static: it reads data/site.json and data/<category>.json, which the daily job
replaces. This only needs re-running when the page itself changes. Data files the page no
longer reads (DATA_FILES lists the ones it does) are removed from the Space.
"""
import re
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

SPACE = "MiniMaxAI/ecosystem"
KEEP = ("data/", "README.md", ".gitattributes")
DATA_FILES = re.compile(r"data/(site|video|language|image|music|audio)\.json")

subprocess.run(["npm", "run", "build"], cwd=ROOT / "web", check=True)
dist = ROOT / "web" / "dist"
files = [p for p in dist.rglob("*") if p.is_file() and not p.relative_to(dist).as_posix().startswith("data/")]
local = {p.relative_to(dist).as_posix() for p in files}
remote = set(api.list_repo_files(SPACE, repo_type="space"))
ops = [CommitOperationAdd(path_in_repo=p.relative_to(dist).as_posix(), path_or_fileobj=str(p)) for p in files]
ops += [CommitOperationDelete(path_in_repo=f) for f in sorted(remote - local)
        if not f.startswith(KEEP) or (f.startswith("data/") and not DATA_FILES.fullmatch(f))]
api.create_commit(SPACE, ops, repo_type="space", commit_message="dashboard page")
print(f"uploaded {len(local)} files, removed {len(ops) - len(local)}")