Skip to content

Commit 692825d

Browse files
authored
Update doc build to correctly get version (#15540)
- Update the theme version to to pull the wheel from pypi - Change how we obtain the version in the CI. - Updated to properly parse `RELEASE` variable - Fixed `Makefile` to use `RELEASE=true` instead of `RELEASE=1` for consistency - Workflow sets `RELEASE=true` only for tagged releases (e.g., `v1.1.0`) - Main branch builds with `<meta name="robots" content="noindex">` tag - Release builds remain indexable by search engines cc @mergennachin @byjlw
1 parent 7771799 commit 692825d

File tree

5 files changed

+56
-30
lines changed

5 files changed

+56
-30
lines changed

.ci/docker/requirements-ci.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ sphinx-reredirects==0.1.4
3030
matplotlib>=3.9.4
3131
sphinx-copybutton==0.5.2
3232
# PyTorch Theme
33-
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git@pytorch_sphinx_theme2#egg=pytorch_sphinx_theme2
34-
33+
pytorch_sphinx_theme2==0.2.0
3534
# script unit test requirements
3635
yaspin==3.1.0

.github/workflows/doc-build.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ jobs:
4646
export CHANNEL=nightly
4747
fi
4848
49-
# Get the version of ExecuTorch from REF_NAME and save as ET_VERSION_DOCS
50-
# ET_VERSION_DOCS will be pulled during the doc build to add to the version dropdown
51-
# on the website. See docs/source/conf.py for details
52-
49+
# Set RELEASE environment variable for tagged releases
5350
GITHUB_REF=${{ github.ref }}
54-
echo "$GITHUB_REF"
55-
export ET_VERSION_DOCS="${GITHUB_REF}"
56-
echo "$ET_VERSION_DOCS"
51+
if [[ "${GITHUB_REF}" =~ ^refs/tags/v[0-9]+\.[0-9]+ ]]; then
52+
export RELEASE=true
53+
echo "Building release docs (RELEASE=true)"
54+
else
55+
export RELEASE=false
56+
echo "Building main docs (RELEASE=false)"
57+
fi
5758
5859
set -eux
5960

.mypy.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ ignore_missing_imports = True
7474
[mypy-pytorch_sphinx_theme]
7575
ignore_missing_imports = True
7676

77+
[mypy-pytorch_sphinx_theme2]
78+
ignore_missing_imports = True
79+
80+
[mypy-executorch.version]
81+
ignore_missing_imports = True
82+
7783
[mypy-ruamel]
7884
ignore_missing_imports = True
7985

docs/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ BUILDDIR = _build
1313
html-noplot:
1414
$(SPHINXBUILD) -D plot_gallery=0 -b html $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
1515

16+
html-stable:
17+
# Stable differs from 'make html' in that it shows the release version
18+
# instead of "main (version)" in the docs and version switcher.
19+
# See conf.py for more details.
20+
RELEASE=true $(MAKE) html
21+
1622
help:
1723
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1824

docs/source/conf.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,40 @@
7676

7777
html_favicon = "_static/img/executorch-chip-logo.svg"
7878

79-
# Get ET_VERSION_DOCS during the build.
80-
et_version_docs = os.environ.get("ET_VERSION_DOCS", None)
81-
print(f"et_version_docs: {et_version_docs}")
82-
83-
# The code below will cut version displayed in the dropdown like this:
84-
# By default, set to "main".
85-
# If it's a tag like refs/tags/v1.2.3-rc4 or refs/tags/v1.2.3, then
86-
# cut to 1.2
87-
# the version varible is used in layout.html: https://github.com/pytorch/executorch/blob/main/docs/source/_templates/layout.html#L29
88-
version = release = "main"
89-
if et_version_docs:
90-
if et_version_docs.startswith("refs/tags/v"):
91-
version = ".".join(
92-
et_version_docs.split("/")[-1].split("-")[0].lstrip("v").split(".")[:2]
93-
)
94-
elif et_version_docs.startswith("refs/heads/release/"):
95-
version = et_version_docs.split("/")[-1]
96-
print(f"Version: {version}")
97-
html_title = " ".join((project, version, "documentation"))
79+
# Import executorch version
80+
# Adopted from PyTorch docs pattern
81+
from executorch import version as et_version # type: ignore[attr-defined]
82+
83+
executorch_version = str(et_version.__version__)
84+
85+
# Check if this is a release build from environment variable
86+
# The workflow sets RELEASE=true for tagged releases, RELEASE=false otherwise
87+
# We need to properly parse the string as a boolean (any non-empty string is truthy in Python)
88+
RELEASE = os.environ.get("RELEASE", "false").lower() == "true"
89+
90+
# The version info for the project you're documenting, acts as replacement for
91+
# |version| and |release|, also used in various other places throughout the
92+
# built documents.
93+
#
94+
# The short X.Y version.
95+
version = "main"
96+
# The full version, including alpha/beta/rc tags.
97+
release = "main"
98+
99+
# Customized html_title here.
100+
# Default is " ".join(project, release, "documentation") if not set
101+
if RELEASE:
102+
# Turn 0.8.0a0+a90e907 into 0.8
103+
# Note: the release candidates should no longer have the aHASH suffix, but in any
104+
# case we wish to leave only major.minor, even for rc builds.
105+
version = ".".join(executorch_version.split("+")[0].split(".")[:2])
106+
html_title = " ".join((project, version, "documentation"))
107+
release = version
108+
109+
switcher_version = "main" if not RELEASE else version
110+
111+
print(f"executorch_version: {executorch_version}")
112+
print(f"Version: {version}, RELEASE: {RELEASE}")
98113

99114
html_baseurl = "https://docs.pytorch.org/executorch/" # needed for sphinx-sitemap
100115
sitemap_locales = [None]
@@ -176,8 +191,6 @@
176191
# documentation.
177192
#
178193

179-
switcher_version = version
180-
181194
html_theme_options = {
182195
"logo": {
183196
"image_light": "_static/img/et-logo.png",
@@ -242,6 +255,7 @@
242255
"display_version": True,
243256
}
244257

258+
245259
# Add any paths that contain custom static files (such as style sheets) here,
246260
# relative to this directory. They are copied after the builtin static files,
247261
# so a file named "default.css" will overwrite the builtin "default.css".

0 commit comments

Comments
 (0)