8000 Populate `html_context` with `READTHEDOCS_*` environment variables (#… · python-sidebar/python_rtd_theme@cf898d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf898d3

Browse files
authored
Populate html_context with READTHEDOCS_* environment variables (readthedocs#1581)
* Populate `html_context` with `READTHEDOCS_*` environment variables Closes readthedocs#1578 * Typo
1 parent 4255743 comm
10000
it cf898d3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sphinx_rtd_theme/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
From https://github.com/ryan-roemer/sphinx-bootstrap-theme.
55
"""
66

7+
import os
78
from os import path
89
from sys import version_info as python_version
910

@@ -36,6 +37,15 @@ def extend_html_context(app, pagename, templatename, context, doctree):
3637
# Add ``sphinx_version_info`` tuple for use in Jinja templates
3738
context['sphinx_version_info'] = sphinx_version
3839

40+
# Inject all the Read the Docs environment variables in the context:
41+
# https://docs.readthedocs.io/en/stable/reference/environment-variables.html
42+
context['READTHEDOCS'] = os.environ.get("READTHEDOCS", False) == "True"
43+
if context['READTHEDOCS']:
44+
for key, value in os.environ.items():
45+
if key.startswith("READTHEDOCS_"):
46+
context[key] = value
47+
48+
3949

4050
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
4151
def setup(app):

0 commit comments

Comments
 (0)
0