Download code/scripts/deploy_space.py from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/2f2f79ea953e63c62ef734e13295dbf6c7628395/code/scripts/deploy_space.py
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@2f2f79ea953e63c62ef734e13295dbf6c7628395/code/scripts/deploy_space.py
-
curl -L -o deploy_space.py https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/2f2f79ea953e63c62ef734e13295dbf6c7628395/code/scripts/deploy_space.py
1.57 kB
| """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)}") | |