From 6708c9a7d963fa45fca216df396a0131ff3c0e4f Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 31 Jul 2024 16:53:35 +0200 Subject: [PATCH 1/2] Populate `html_context` with `READTHEDOCS_*` environment variables Closes #1578 --- sphinx_rtd_theme/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sphinx_rtd_theme/__init__.py b/sphinx_rtd_theme/__init__.py index 0d7d00b7d..94a261902 100644 --- a/sphinx_rtd_theme/__init__.py +++ b/sphinx_rtd_theme/__init__.py @@ -4,6 +4,7 @@ From https://github.com/ryan-roemer/sphinx-bootstrap-theme. """ +import os from os import path from sys import version_info as python_version @@ -36,6 +37,15 @@ 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 + # Inject all the Read the Docs environment variables in the context: + # https://docs.readthedocs.io/en/stable/reference/environment-variables.html + context['READTHEDOCS'] = os.environ.get("READTHEDOCS", False) == "True" + if context['READTHEDOCS']: + for key, value in os.environ: + if key.startswith("READTHEDOCS_"): + context[key] = value + + # See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package def setup(app): From 6652b6dc29293bb97c07fee37721751f368238ba Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 1 Aug 2024 19:13:25 +0200 Subject: [PATCH 2/2] Typo --- sphinx_rtd_theme/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_rtd_theme/__init__.py b/sphinx_rtd_theme/__init__.py index 94a261902..6b491191c 100644 --- a/sphinx_rtd_theme/__init__.py +++ b/sphinx_rtd_theme/__init__.py @@ -41,7 +41,7 @@ def extend_html_context(app, pagename, templatename, context, doctree): # https://docs.readthedocs.io/en/stable/reference/environment-variables.html context['READTHEDOCS'] = os.environ.get("READTHEDOCS", False) == "True" if context['READTHEDOCS']: - for key, value in os.environ: + for key, value in os.environ.items(): if key.startswith("READTHEDOCS_"): context[key] = value