Files
alexm 401084bab3
Test / gate (push) Failing after 19m0s
Initial commit
2026-11-12 22:23:54 -05:00

50 lines
2.1 KiB
Python

#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
# SPDX-License-Identifier: Apache-2.0
"""Zip the repository for sharing: the files git tracks, plus new files it does not ignore.
pixi run package # writes package/pplus-core-<commit>.zip
Nothing git ignores goes in: no .DS_Store, __pycache__, scratch/, dist/, site/, node_modules/ or
.pixi/. Files are stored under a top folder named pplus-core/.
Standard library only, like the corpus pipeline.
"""
import pathlib
import subprocess
import sys
import zipfile
ROOT = pathlib.Path(__file__).resolve().parent.parent
def git(*args: str) -> str:
return subprocess.run(["git", *args], cwd=ROOT, check=True, capture_output=True, text=True).stdout
def main() -> int:
try:
commit = git("rev-parse", "--short", "HEAD").strip()
except (subprocess.CalledProcessError, FileNotFoundError):
print("package: this needs a git checkout (git init and commit first)", file=sys.stderr)
return 1
dirty = bool(git("status", "--porcelain").strip())
names = sorted(set(git("ls-files", "-z", "--cached", "--others", "--exclude-standard").split("\0")) - {""})
# pplus-library (library/) is a submodule: take the files its checkout tracks, so the zip tests on its own
if (ROOT / "library" / ".git").exists():
tracked = subprocess.run(["git", "ls-files", "-z"], cwd=ROOT / "library", check=True, capture_output=True, text=True).stdout
names += [f"library/{n}" for n in tracked.split("\0") if n]
names = [n for n in names if (ROOT / n).is_file()]
out_dir = ROOT / "package"
out_dir.mkdir(exist_ok=True)
out = out_dir / f"pplus-core-{commit}{'-dirty' if dirty else ''}.zip"
with zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED) as z:
for n in names:
z.write(ROOT / n, f"pplus-core/{n}")
size = out.stat().st_size / 1e6
print(f"wrote {out.relative_to(ROOT)}: {len(names)} files, {size:.1f} MB{' (with uncommitted changes)' if dirty else ''}")
return 0
if __name__ == "__main__":
sys.exit(main())