Skip to content

Commit 76c69dd

Browse files
committed
docs: show version at top of first page
Having the Open MPI version at the top of the front index page is a good, obvious visual indicator to the user to which version these docs apply. Usually, the version we display is derived from the contents of the VERSION file. However, when releasing Open MPI, we typically go back and create an annotated git tag at a commit prior to the head of the release branch. This means that there is no git commit where the VERSION file has an empty "greek" version. As such, use the following scheme to determine what version string to use for the RST macro "|ompi_ver|": 1. If there is an environment variable named READTHEDOCS_VERSION, use that (this env variable is documented here: https://docs.readthedocs.io/en/stable/builds.html#build-environment) 2. Otherwise, use the contents of the Open MPI VERSION file Signed-off-by: Jeff Squyres <[email protected]>
1 parent 0b04e2b commit 76c69dd

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

docs/conf.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,63 @@
4141
ompi_key, ompi_val = ompi_line.split("=")
4242
ompi_data[ompi_key.strip()] = ompi_val.strip()
4343

44-
# "release" is a sphinx config variable -- assign it to the computed
45-
# Open MPI version number.
46-
series = f"{ompi_data['major']}.{ompi_data['minor']}.x"
47-
release = f"{ompi_data['major']}.{ompi_data['minor']}.{ompi_data['release']}{ompi_data['greek']}"
48-
44+
ompi_series = f"v{ompi_data['major']}.{ompi_data['minor']}.x"
45+
ompi_ver = f"v{ompi_data['major']}.{ompi_data['minor']}.{ompi_data['release']}{ompi_data['greek']}"
46+
47+
# "release" is a sphinx config variable: assign it to the computed
48+
# Open MPI version number. The ompi_ver string begins with a "v"; the
49+
# Sphinx release variable should not include this prefix "v".
50+
release = ompi_ver[1:]
51+
52+
# If we are building in a ReadTheDocs.io environment, there will be a
53+
# READTHEDOCS environment variables that tell us what version to use.
54+
# Relevant RTD env variables (documented
55+
# https://docs.readthedocs.io/en/stable/builds.html#build-environment):
56+
#
57+
# - READTHEDOCS: will be "True"
58+
# - READTHEDOCS_VERSION: The RTD slug of the version which is being
59+
# built (e.g., "latest")
60+
# - READTHEDOCS_VERSION_NAME: Corresponding version name as displayed
61+
# in RTD's version switch menu (e.g., "stable")
62+
# - READTHEDOCS_VERSION_TYPE: Type of the event triggering the build
63+
# (e.g., "branch", "tag", "external" (for PRs), or "unknown").
64+
#
65+
# If we're building in an RTD environment for a tag or external (i.e.,
66+
# PR), use the RTD version -- not what we just read from the VERSIONS
67+
# file.
68+
import os
69+
key = 'READTHEDOCS'
70+
if key in os.environ and os.environ[key] == 'True':
71+
print("OMPI: found ReadTheDocs build environment")
72+
73+
rtd_v = os.environ['READTHEDOCS_VERSION']
74+
if os.environ['READTHEDOCS_VERSION_TYPE'] == 'external':
75+
# Make "release" be shorter than the full "ompi_ver" value.
76+
release = f'PR #{rtd_v}'
77+
ompi_ver += f' (Github PR #{rtd_v})'
78+
else:
79+
ompi_ver = rtd_v
80+
81+
# The "release" Sphinx variable is supposed to be expressed as
82+
# a simple value, such as "A.B.C[rcX]" (without a leading
83+
# "v"). The ompi_ver value will be one of two things:
84+
#
85+
# - a git branch name (of the form "vA.B.x")
86+
# - a git tag (of the form "A.B.C[rcX]")
87+
#
88+
# If there's a leading "v", we need to strip it.
89+
release = ompi_ver
90+
if ompi_ver[0] == 'v':
91+
release = ompi_ver[1:]
92+
93+
# Override the branch names "master" and "main" (that would have
94+
# come from the ReadTheDocs version slug) to be "head of
95+
# development".
96+
if release == 'main' or release == 'master':
97+
ompi_ver = 'head of development'
98+
99+
print(f"OMPI: release = {release}")
100+
print(f"OMPI: ompi_ver = {ompi_ver}")
49101

50102
# -- General configuration ---------------------------------------------------
51103

@@ -125,6 +177,6 @@ def _doit(topdir):
125177
.. |rarrow| unicode:: U+02192 .. Right arrow
126178
127179
.. |year| replace:: {year}
128-
.. |ompi_ver| replace:: v{release}
129-
.. |ompi_series| replace:: v{series}
180+
.. |ompi_ver| replace:: {ompi_ver}
181+
.. |ompi_series| replace:: {ompi_series}
130182
"""

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. image:: openmpi_logo.png
22
:align: right
33

4-
Open MPI
5-
========
4+
Open MPI |ompi_ver|
5+
===================
66

77
`The Open MPI Project <https://www.open-mpi.org/>`_ is an open source
88
implementation of the `Message Passing Interface (MPI) specification

0 commit comments

Comments
 (0)