Skip to content

Commit ed565ce

Browse files
authored
Fix missing directory of document for new tag v0.9.0 (#776)
The v0.9.0 conf.py (introduced in #775) dynamically loads the version from python/mscclpp/_version.py. This file is generated at build time by setuptools_scm and is listed in .gitignore — it is never committed to the repo. Earlier tags (v0.8.0 and below) used a hardcoded release (e.g., "v0.8.0") in conf.py, so they had no dependency on generated files. sphinx-multiversion checks out each tag using git archive, which only extracts committed files. Since _version.py is not committed, the v0.9.0 checkout is missing it, and conf.py crashes on import. All future tags will have this same problem. **Three changes:** 1. docs/build_multiversion.py (new): A wrapper around sphinx-multiversion that monkey-patches copy_tree to generate _version.py in each tag checkout after extraction. The version string is parsed from the tag name (e.g., v0.9.0 → __version__ = "0.9.0"). 2. Makefile: The multiversion target now calls build_multiversion.py instead of sphinx-multiversion directly. 3. conf.py: Added a fallback so that if _version.py doesn't exist, it reads the version from the VERSION file instead. This makes conf.py resilient for any future scenario where _version.py is missing. **Testing** Verified locally: • make multiversion now successfully builds all 11 versions (v0.4.0 through v0.9.0) • v0.9.0 docs are correctly generated under _build/html/v0.9.0/ Version selector shows v0.9.0 as latest
1 parent 8896cd9 commit ed565ce

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# from the environment for the first two.
66
SPHINXOPTS ?=
77
SPHINXBUILD ?= sphinx-build
8-
SPHINXMULTIVERSION ?= sphinx-multiversion
8+
SPHINXMULTIVERSION ?= python3 build_multiversion.py
99
SOURCEDIR = .
1010
BUILDDIR = _build
1111

docs/build_multiversion.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
5+
"""Wrapper around sphinx-multiversion that patches copy_tree to generate
6+
_version.py in each tag checkout. This is needed because setuptools_scm
7+
generates _version.py at build time, but sphinx-multiversion uses
8+
`git archive` which only contains committed files.
9+
10+
Usage (called by Makefile):
11+
python3 build_multiversion.py <sourcedir> <outputdir> [sphinx-opts...]
12+
"""
13+
14+
import os
15+
import re
16+
import subprocess
17+
import sys
18+
19+
import sphinx_multiversion.git as smv_git
20+
from sphinx_multiversion import main as smv_main
21+
22+
# Save the original copy_tree
23+
_original_copy_tree = smv_git.copy_tree
24+
25+
26+
def _patched_copy_tree(gitroot, src, dst, reference, sourcepath="."):
27+
"""Call original copy_tree, then generate _version.py from the VERSION file."""
28+
_original_copy_tree(gitroot, src, dst, reference, sourcepath)
29+
30+
# Extract version from the tag name (e.g., "v0.9.0" -> "0.9.0")
31+
refname = getattr(reference, "refname", "") or ""
32+
match = re.search(r"v(\d+\.\d+\.\d+)", refname)
33+
if not match:
34+
return
35+
36+
version = match.group(1)
37+
version_py_dir = os.path.join(dst, "python", "mscclpp")
38+
if os.path.isdir(version_py_dir):
39+
version_py = os.path.join(version_py_dir, "_version.py")
40+
if not os.path.exists(version_py):
41+
with open(version_py, "w") as f:
42+
f.write(f'__version__ = "{version}"\n')
43+
44+
45+
# Monkey-patch
46+
smv_git.copy_tree = _patched_copy_tree
47+
48+
if __name__ == "__main__":
49+
sys.exit(smv_main(sys.argv[1:]))

0 commit comments

Comments
 (0)