Skip to content

Commit 16c9628

Browse files
authored
[Docs] Update website theme for newer Sphinx (#22872)
Fixes #15365 Replaces the custom theme with the last version of sphinx_rtd_theme, and then adds the changes found by diffing the emscripten custom theme with sphinx_rtd_theme version 0.1.6.
1 parent 17289b5 commit 16c9628

38 files changed

+11045
-1105
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exclude =
77
./tools/scons/, # third-party code
88
./test/third_party/, # third-party code
99
./site/source/conf.py,
10+
./site/source/_themes/,
1011
./system/lib/, # system libraries
1112
./cache/, # download/built content
1213
.git

.mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exclude = (?x)(
66
third_party |
77
conf\.py |
88
emrun\.py |
9+
site/source/_themes/ |
910
tools/scons/site_scons/site_tools/emscripten/__init__\.py |
1011
site/source/get_wiki\.py |
1112
test/parse_benchmark_output\.py

requirements-dev.txt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,8 @@ lxml==4.9.2
1717

1818
# This version is mentioned in `site/source/docs/site/about.rst`.
1919
# Please keep them in sync.
20-
sphinx==2.4.4
21-
# See https://github.com/emscripten-core/emscripten/issues/21590
22-
sphinxcontrib-applehelp<=1.0.4
23-
sphinxcontrib-devhelp<=1.0.2
24-
sphinxcontrib-htmlhelp<=2.0.0
25-
sphinxcontrib-serializinghtml<=1.1.5
26-
sphinxcontrib-qthelp<=1.0.3
27-
alabaster<=0.7.12
28-
pygments==2.17.2
29-
# See https://github.com/readthedocs/readthedocs.org/issues/9038
30-
jinja2<3.1
31-
32-
# Pin docutils because newer versions are not compatible with sphinx 2.4.4
33-
docutils==0.17.1
20+
sphinx==7.1.2
21+
sphinxcontrib-jquery==4.0
3422

3523
# Needed by test/test_sockets.py
3624
websockify==0.10.0

site/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
# You can set these variables from the command line.
55
SPHINXOPTS = -W
66
SPHINXBUILD = sphinx-build
7-
SPHINXVERSION = 2.4.4
7+
SPHINXVERSION = 7.1.2
88
PAPER =
99
BUILDDIR = build
1010

1111
# User-friendly check for sphinx-build
1212
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
13-
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx version 2.4.4 installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
13+
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx version 7.1.2 installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
1414
endif
1515

1616
ifneq ($(shell $(SPHINXBUILD) --version), $(SPHINXBUILD) $(SPHINXVERSION))

site/source/_themes/emscripten_sphinx_rtd_theme/__init__.py

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,109 @@
33
# University of Illinois/NCSA Open Source License. Both these licenses can be
44
# found in the LICENSE file.
55

6-
"""Sphinx ReadTheDocs theme.
6+
"""
7+
Sphinx Read the Docs theme.
78
89
From https://github.com/ryan-roemer/sphinx-bootstrap-theme.
9-
1010
"""
11+
1112
import os
13+
from os import path
14+
from sys import version_info as python_version
1215

13-
VERSION = (0, 1, 6)
16+
from sphinx import version_info as sphinx_version
17+
from sphinx.locale import _
18+
from sphinx.util.logging import getLogger
1419

15-
__version__ = ".".join(str(v) for v in VERSION)
20+
21+
__version__ = '3.0.1'
1622
__version_full__ = __version__
1723

24+
logger = getLogger(__name__)
25+
1826

1927
def get_html_theme_path():
2028
"""Return list of HTML theme paths."""
21-
cur_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
29+
logger.warning(
30+
_('Calling get_html_theme_path is deprecated. If you are calling it to define html_theme_path, you are safe to remove that code.')
31+
)
32+
33+
cur_dir = path.abspath(path.dirname(path.dirname(__file__)))
2234
return cur_dir
35+
36+
37+
def config_initiated(app, config):
38+
theme_options = config.html_theme_options or {}
39+
if theme_options.get('canonical_url'):
40+
logger.warning(
41+
_('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
42+
)
43+
44+
if theme_options.get("analytics_id"):
45+
logger.warning(
46+
_('The analytics_id option is deprecated, use the sphinxcontrib-googleanalytics extension instead.')
47+
)
48+
49+
if theme_options.get("analytics_anonymize_ip"):
50+
logger.warning(
51+
_('The analytics_anonymize_ip option is deprecated, use the sphinxcontrib-googleanalytics extension instead.')
52+
)
53+
54+
if "extra_css_files" in config.html_context:
55+
logger.warning(
56+
_('The extra_css_file option is deprecated, use the html_css_files option from Sphinx instead.')
57+
)
58+
59+
60+
def extend_html_context(app, pagename, templatename, context, doctree):
61+
# Add ``sphinx_version_info`` tuple for use in Jinja templates
62+
context['sphinx_version_info'] = sphinx_version
63+
64+
# Inject all the Read the Docs environment variables in the context:
65+
# https://docs.readthedocs.io/en/stable/reference/environment-variables.html
66+
context['READTHEDOCS'] = os.environ.get("READTHEDOCS", False) == "True"
67+
if context['READTHEDOCS']:
68+
for key, value in os.environ.items():
69+
if key.startswith("READTHEDOCS_"):
70+
context[key] = value
71+
72+
73+
74+
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
75+
def setup(app):
76+
if python_version[0] < 3:
77+
logger.error("Python 2 is not supported with sphinx_rtd_theme, update to Python 3.")
78+
79+
app.require_sphinx('6.0')
80+
if app.config.html4_writer:
81+
logger.error("'html4_writer' is not supported with sphinx_rtd_theme.")
82+
83+
# Since Sphinx 6, jquery isn't bundled anymore and we need to ensure that
84+
# the sphinxcontrib-jquery extension is enabled.
85+
# See: https://dev.readthedocs.io/en/latest/design/sphinx-jquery.html
86+
if sphinx_version >= (6, 0, 0):
87+
# Documentation of Sphinx guarantees that an extension is added and
88+
# enabled at most once.
89+
# See: https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.setup_extension
90+
app.setup_extension("sphinxcontrib.jquery")
91+
# However, we need to call the extension's callback since setup_extension doesn't do it
92+
# See: https://github.com/sphinx-contrib/jquery/issues/23
93+
from sphinxcontrib.jquery import add_js_files as jquery_add_js_files
94+
jquery_add_js_files(app, app.config)
95+
96+
# Register the theme that can be referenced without adding a theme path
97+
app.add_html_theme('sphinx_rtd_theme', path.abspath(path.dirname(__file__)))
98+
99+
# Add Sphinx message catalog for newer versions of Sphinx
100+
# See http://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_message_catalog
101+
rtd_locale_path = path.join(path.abspath(path.dirname(__file__)), 'locale')
102+
app.add_message_catalog('sphinx', rtd_locale_path)
103+
app.connect('config-inited', config_initiated)
104+
105+
# sphinx emits the permalink icon for headers, so choose one more in keeping with our theme
106+
app.config.html_permalinks_icon = "\uf0c1"
107+
108+
# Extend the default context when rendering the templates.
109+
app.connect("html-page-context", extend_html_context)
110+
111+
return {'parallel_read_safe': True, 'parallel_write_safe': True}

0 commit comments

Comments
 (0)