Skip to content

Commit 5dd94b9

Browse files
committed
Add scripts to build old versions of documentation
1 parent 3dc09d7 commit 5dd94b9

8 files changed

Lines changed: 164 additions & 2 deletions

File tree

build-docs.just

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Make rustdoc warnings fatal
22
export RUSTDOCFLAGS := "-D warnings"
33

4-
# Build all documentation
5-
all: cli-help file-format examples book api
4+
# Build all documentation, except old docs
5+
all: cli-help file-format examples versions book api
6+
7+
# Build all documentation, including old docs
8+
all_with_old: all old
69

710
# Build book
811
book:
@@ -33,3 +36,15 @@ file-format *ARGS:
3336
examples:
3437
@echo Building docs for examples
3538
@uv run docs/generate_example_docs.py
39+
40+
# Build TOC for old versions
41+
versions:
42+
@echo Building TOC for old versions of documentation
43+
@uv run docs/generate_versions_docs.py
44+
45+
# Build documentation for previous releases
46+
old:
47+
@# Clean output dir
48+
@rm -rf book/release
49+
50+
@uv run docs/build_old_docs.py

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Generated documentation files
22
command_line_help.md
33
examples.md
4+
versions.md

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
- [Release notes](release_notes/README.md)
2424
- [MUSE2 v2.0.0 (October 14, 2025)](release_notes/v2.0.0.md)
2525
- [Next unreleased version](release_notes/upcoming.md)
26+
- [Documentation for old versions](versions.md)

docs/build_old_docs.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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()

docs/generate_versions_docs.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
# /// script
3+
# dependencies = [
4+
# "jinja2",
5+
# ]
6+
# ///
7+
#
8+
# A script to generate the versions.md file, listing links to old versions of documentation.
9+
10+
import sys
11+
from pathlib import Path
12+
13+
from jinja2 import Environment, FileSystemLoader
14+
15+
DOCS_DIR = Path(__file__).parent.absolute()
16+
17+
sys.path.append(str(DOCS_DIR / "release"))
18+
from release import get_releases # noqa: E402
19+
20+
21+
def generate_versions_md() -> None:
22+
"""Write the versions.md file."""
23+
print("Generating versions.md")
24+
env = Environment(loader=FileSystemLoader(DOCS_DIR / "templates"))
25+
template = env.get_template("versions.md.jinja")
26+
out = template.render(releases=get_releases())
27+
28+
with (DOCS_DIR / "versions.md").open("w") as f:
29+
f.write(out)
30+
31+
32+
if __name__ == "__main__":
33+
generate_versions_md()

docs/release/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Common functionality for working with different versions."""
2+
3+
import re
4+
import subprocess as sp
5+
6+
7+
def is_release_tag(tag: str) -> bool:
8+
"""Whether the git tag indicates a version.
9+
10+
We don't include pre-releases.
11+
"""
12+
return re.match(r"^v[0-9]+\.[0-9]+\.[0-9]+$", tag) is not None
13+
14+
15+
def get_releases() -> list[str]:
16+
"""Get all release tags for this repo."""
17+
ret = sp.run(("git", "tag"), capture_output=True, check=True, encoding="utf-8")
18+
return [tag for tag in ret.stdout.splitlines() if is_release_tag(tag)]

docs/release/patches/v2.0.0.patch

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
From 3129c56aea05dd2b7e88c76bb2050fded0529243 Mon Sep 17 00:00:00 2001
2+
From: Aurash Karimi <a.karimi@imperial.ac.uk>
3+
Date: Wed, 19 Nov 2025 09:48:11 +0000
4+
Subject: [PATCH] remove unrecognised parameter
5+
6+
---
7+
book.toml | 1 -
8+
1 file changed, 1 deletion(-)
9+
10+
diff --git a/book.toml b/book.toml
11+
index 41fba09c..84d181ee 100644
12+
--- a/book.toml
13+
+++ b/book.toml
14+
@@ -1,7 +1,6 @@
15+
[book]
16+
authors = ["Alex Dewar"]
17+
language = "en"
18+
-multilingual = false
19+
src = "docs"
20+
title = "MUSE2"
21+
22+
--
23+
2.53.0

docs/templates/versions.md.jinja

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Previous versions of documentation
2+
3+
Previous versions of the MUSE2 documentation are available below.
4+
{% for release in releases %}
5+
- [{{ release }}](release/{{ release }}/index.html)
6+
{%- endfor %}

0 commit comments

Comments
 (0)