gs_playground/scripts/export_real2sim_source.py

66 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Export an allowlisted source snapshot, without git history or legacy assets."""
from __future__ import annotations
import argparse
import hashlib
import json
import re
import shutil
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--output", type=Path, required=True)
args = parser.parse_args()
out = args.output.resolve()
if out.exists():
raise SystemExit("Output must not exist; refusing to overwrite a checkout.")
paths = subprocess.check_output(["git", "ls-files", "-z"], cwd=ROOT).decode().split("\0")
allowed = []
for path in paths:
if path in {"LICENSE", "THIRD_PARTY_NOTICES.md", "CONTRIBUTING.md", "SECURITY.md", "docs/real2sim.md"}:
allowed.append(path)
elif path.startswith(("real2sim/", "scripts/real2sim", "tests/test_real2sim", "configs/real2sim")):
allowed.append(path)
# Include reviewed release documents even before their first commit.
for path in ["THIRD_PARTY_NOTICES.md", "CONTRIBUTING.md", "SECURITY.md"]:
if path not in allowed:
allowed.append(path)
for path in allowed:
target = out / path
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(ROOT / path, target)
if path == "docs/real2sim.md":
# Omit private evidence images, keeping their captions without broken links.
target.write_text(re.sub(
r"!\[([^\]]*)\]\(assets/real2sim-video-optimization/[^)]+\)",
r"*Historical evidence image omitted from source-only release: \1.*",
target.read_text(encoding="utf-8"),
), encoding="utf-8")
shutil.copy2(ROOT / "docs/open-source/PUBLIC_README.md", out / "README.md")
shutil.copy2(ROOT / "docs/open-source/requirements-cpu.txt", out / "requirements-cpu.txt")
workflow = out / ".github/workflows/cpu-tests.yml"
workflow.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(ROOT / "docs/open-source/cpu-tests.yml", workflow)
(out / ".gitignore").write_text(".venv/\n__pycache__/\n*.pyc\noutputs/\nworkdirs/\nartifacts/\n.env\n.env.*\n")
manifest = {
"source_commit": subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT).decode().strip(),
"description": "Allowlisted working-tree source snapshot; release documents may be newer than source_commit.",
"excluded": ["git history", "robot assets", "model weights", "SDK binaries", "private inputs", "cloud outputs"],
"sha256": {str(p.relative_to(out)): hashlib.sha256(p.read_bytes()).hexdigest()
for p in sorted(out.rglob("*")) if p.is_file()},
}
(out / "SOURCE_MANIFEST.json").write_text(json.dumps(manifest, indent=2)+"\n")
print(f"Exported {len(manifest['sha256'])} files to {out}")
return 0
if __name__ == "__main__":
raise SystemExit(main())