From 20607e85259f5a1885505807f932fc16cdad9449 Mon Sep 17 00:00:00 2001 From: Benjamin Balder Bach Date: Tue, 11 Oct 2022 14:01:07 +0200 Subject: [PATCH 1/2] Additions to Tox and Circle CI matrix (#1349) * Refines tox matrix, adds a new target "sphinxdev" that can test the latest upstream development branch * Adds missing tox environments in circle ci config * Remove odd undefined py2 and py3 tox environments --- .circleci/config.yml | 2 +- tox.ini | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3963cae26..ac8a66583 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,7 +11,7 @@ commands: type: string sphinx-version: type: string - default: "16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,50,51,52,latest" + default: "16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,latest" steps: - checkout - run: pip install --user tox diff --git a/tox.ini b/tox.ini index 3c00b01eb..356006e44 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,10 @@ [tox] envlist = - py{2,27}-sphinx{16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,42,43,44,45,50,51}{-html4,-html5,}{-qa,} - py{3,36,37,38,39}-sphinx{16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,42,43,44,45,50,51,latest}{-html4,-html5,}{-qa,} - py{310}-sphinx{42,43,44,45,50,51,latest}{-html4,-html5,}{-qa,} + # Python 2.7 support was removed in Sphinx 2 + py{27}-sphinx{16,17,18}{-html4,-html5,}{-qa,} + py{36,37,38,39}-sphinx{16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,latest}{-html4,-html5,}{-qa,} + # Python 3.10 working from Sphinx 4.2 and up + py{310}-sphinx{42,43,44,45,50,51,52}{-html4,-html5,latest}{-qa,} [testenv] setev = @@ -35,8 +37,12 @@ deps = sphinx50: Sphinx>=5.0,<5.1 sphinx51: Sphinx>=5.1,<5.2 sphinx52: Sphinx>=5.2,<5.3 + # All these Sphinx versions actually break since docutils 0.18, so we need to add this upper bound + # Projects using these Sphinx versions will have to do the same + # See: https://github.com/readthedocs/sphinx_rtd_theme/pull/1304 sphinx{16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,42}: docutils<0.18 sphinxlatest: Sphinx + sphinxdev: https://github.com/sphinx-doc/sphinx/archive/refs/heads/master.zip commands = pytest {posargs} tests/ !html4: sphinx-build -b html -Dhtml4_writer=0 -d {envtmpdir}/doctrees docs/ {envtmpdir}/html From c6fa4e7a40a2b7428e9b1085cd994ec24f089368 Mon Sep 17 00:00:00 2001 From: Benjamin Balder Bach Date: Wed, 12 Oct 2022 20:54:10 +0200 Subject: [PATCH 2/2] Move context logic for layout.html to jinja (#1356) * Revert "Update layout.html to support a sphinx version that is not three-integers (#1345)" This reverts commit 45cf21874fb005ac86206ed26f609cb509eebbb2. * Always slice list before unpacking so number of elements is expected range `map` filter returns a generator that needs to run through the `list` filter before slicing * Let's keep it a 3-tuple but always set 3rd component to -1 -- in case a project was unpacking 3 values --- docs/changelog.rst | 1 + sphinx_rtd_theme/__init__.py | 9 --------- sphinx_rtd_theme/layout.html | 4 ++++ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 3215b4c2e..71d14c08e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -45,6 +45,7 @@ Minor changes * Python 3.10 added to test matrix (#1334) * Supplemental Docker setup for development (#1319) * Most of setup.py migrated to setup.cfg (#1116) +* Jinja2 context variable ``sphinx_version_info`` is now ``(major, minor, -1)``, the patch component is always ``-1``. Reason: It's complicated. (#1345) Incompatible Changes diff --git a/sphinx_rtd_theme/__init__.py b/sphinx_rtd_theme/__init__.py index 9ea323f0c..f31909865 100644 --- a/sphinx_rtd_theme/__init__.py +++ b/sphinx_rtd_theme/__init__.py @@ -31,12 +31,6 @@ def config_initiated(app, config): _('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.') ) - -def extend_html_context(app, pagename, templatename, context, doctree): - # Add ``sphinx_version_info`` tuple for use in Jinja templates - context['sphinx_version_info'] = sphinx_version - - # See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package def setup(app): if python_version[0] < 3: @@ -66,7 +60,4 @@ def setup(app): else: app.config.html_add_permalinks = "\uf0c1" - # Extend the default context when rendering the templates. - app.connect("html-page-context", extend_html_context) - return {'parallel_read_safe': True, 'parallel_write_safe': True} diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index 99ec01b71..bb0c069a2 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -9,6 +9,10 @@ {%- set lang_attr = 'en' if language == None else (language | replace('_', '-')) %} {%- set sphinx_writer = 'writer-html5' if html5_doctype else 'writer-html4' -%} +{# Build sphinx_version_info tuple from sphinx_version string in pure Jinja #} +{%- set (_ver_major, _ver_minor) = (sphinx_version.split('.') | list)[:2] | map('int') -%} +{%- set sphinx_version_info = (_ver_major, _ver_minor, -1) -%} +