From 426fdcabcd84aaa04962416a5e9fff274edc46f9 Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Tue, 13 Jul 2021 20:44:46 -0400 Subject: [PATCH 1/2] HTML Templates: Expose full sphinx version tuple Previously, there was only a string which is problematic when you want to programmatically compare versions for compatibility reasons. --- doc/templating.rst | 11 ++++++++++- sphinx/builders/html/__init__.py | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/templating.rst b/doc/templating.rst index 61b714bfa33..b9f7f19570d 100644 --- a/doc/templating.rst +++ b/doc/templating.rst @@ -371,7 +371,16 @@ in the future. .. data:: sphinx_version - The version of Sphinx used to build. + The version of Sphinx used to build represented as a string for example "3.5.1". + +.. data:: sphinx_version_tuple + + The version of Sphinx used to build represented as a tuple of five elements. + For Sphinx version 3.5.1 beta 3 this would be `(3, 5, 1, 'beta', 3)``. + The fourth element can be one of: ``alpha``, ``beta``, ``rc``, ``final``. + ``final`` always has 0 as the last element. + + .. versionadded:: 4.2 .. data:: style diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index a78d54a1665..980eca3d9b4 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -26,6 +26,7 @@ from docutils.utils import relative_path from sphinx import __display_version__, package_dir +from sphinx import version_info as sphinx_version from sphinx.application import Sphinx from sphinx.builders import Builder from sphinx.config import ENUM, Config @@ -508,7 +509,8 @@ def prepare_writing(self, docnames: Set[str]) -> None: 'script_files': self.script_files, 'language': self.config.language, 'css_files': self.css_files, - 'sphinx_version': __display_version__, + 'sphinx_version': sphinx_version, + 'sphinx_version_tuple': sphinx_version, 'style': self._get_style_filename(), 'rellinks': rellinks, 'builder': self.name, From 4d0f497689212c8bc59f917cab58453d51b32617 Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Wed, 14 Jul 2021 16:20:30 -0400 Subject: [PATCH 2/2] Fix sphinx_version string --- sphinx/builders/html/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 980eca3d9b4..b7295abd0e1 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -509,7 +509,7 @@ def prepare_writing(self, docnames: Set[str]) -> None: 'script_files': self.script_files, 'language': self.config.language, 'css_files': self.css_files, - 'sphinx_version': sphinx_version, + 'sphinx_version': __display_version__, 'sphinx_version_tuple': sphinx_version, 'style': self._get_style_filename(), 'rellinks': rellinks,