Skip to content

Commit

Permalink
HTML Templates: Expose full sphinx version tuple
Browse files Browse the repository at this point in the history
Previously, there was only a string which is problematic
when you want to programmatically compare versions
for compatibility reasons.
  • Loading branch information
Blendify committed Jul 14, 2021
1 parent 9e1b4a8 commit 426fdca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion doc/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 426fdca

Please sign in to comment.