|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# A script to generate documentation for previous releases of MUSE2. |
| 4 | + |
| 5 | +import shutil |
| 6 | +import subprocess as sp |
| 7 | +import sys |
| 8 | +from pathlib import Path |
| 9 | +from tempfile import TemporaryDirectory |
| 10 | + |
| 11 | +REPO_ROOT = Path(__file__).parent.parent.absolute() |
| 12 | +DOCS_DIR = REPO_ROOT / "docs" |
| 13 | + |
| 14 | +sys.path.append(str(DOCS_DIR / "release")) |
| 15 | +from release import get_releases # noqa: E402 |
| 16 | + |
| 17 | + |
| 18 | +def clone_repo_to(dest: Path): |
| 19 | + """Clone this repo somewhere else.""" |
| 20 | + print("Making a copy of repo") |
| 21 | + sp.run(("git", "clone", REPO_ROOT, dest), check=True, capture_output=True) |
| 22 | + |
| 23 | + |
| 24 | +def build_docs_for_release(release: str, repo_path: Path, outdir: Path) -> None: |
| 25 | + """Build documentation for a given release.""" |
| 26 | + print(f"Building docs for {release}") |
| 27 | + |
| 28 | + # Check out release |
| 29 | + sp.run( |
| 30 | + ("git", "-C", str(repo_path), "checkout", release), |
| 31 | + check=True, |
| 32 | + capture_output=True, |
| 33 | + ) |
| 34 | + |
| 35 | + # Apply patch, if there is one |
| 36 | + patch_path = DOCS_DIR / "release" / "patches" / f"{release}.patch" |
| 37 | + if patch_path.exists(): |
| 38 | + sp.run(("git", "-C", str(repo_path), "am", str(patch_path)), check=True) |
| 39 | + |
| 40 | + # Build docs |
| 41 | + sp.run(("just", f"{repo_path!s}/build-docs"), capture_output=True, check=True) |
| 42 | + |
| 43 | + # Move to output directory |
| 44 | + release_outdir = outdir / release |
| 45 | + print(f"Copying to {release_outdir}") |
| 46 | + shutil.move((repo_path / "book"), release_outdir) |
| 47 | + |
| 48 | + |
| 49 | +def build_old_docs() -> None: |
| 50 | + """Build documentation for previous releases.""" |
| 51 | + outdir = REPO_ROOT / "book" / "release" |
| 52 | + outdir.mkdir(parents=True, exist_ok=True) |
| 53 | + |
| 54 | + # Clone this repo to a temporary directory |
| 55 | + tmpdir = TemporaryDirectory() |
| 56 | + repo_path = Path(tmpdir.name) |
| 57 | + clone_repo_to(repo_path) |
| 58 | + |
| 59 | + # Generate documentation for each previous release |
| 60 | + for release in get_releases(): |
| 61 | + build_docs_for_release(release, repo_path, outdir) |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + build_old_docs() |
0 commit comments