"""Build the dashboard page (web/) and upload it to the Space, leaving data/ alone. python scripts/deploy_space.py The page is static: it reads data/index.json and data/.json, which the daily job replaces. This only needs re-running when the page itself changes. """ 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/oss-ecosystem" KEEP = ("data/", "README.md", ".gitattributes") 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)] api.create_commit(SPACE, ops, repo_type="space", commit_message="dashboard page") print(f"uploaded {len(local)} files, removed {len(ops) - len(local)}")