Skip to content

Commit 982681b

Browse files
committed
Load all themes defined via entry points
1 parent 8fe915f commit 982681b

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Release 7.3.2 (in development)
44
Bugs fixed
55
----------
66

7+
* Preload all themes defined via entry points.
8+
Patch by Adam Turner.
79

810
Release 7.3.1 (released Apr 17, 2024)
911
=====================================

sphinx/theming.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __init__(self, app: Sphinx) -> None:
159159
self._load_builtin_themes()
160160
if getattr(app.config, 'html_theme_path', None):
161161
self._load_additional_themes(app.config.html_theme_path)
162+
self._load_entry_point_themes()
162163

163164
def _load_builtin_themes(self) -> None:
164165
"""Load built-in themes."""
@@ -174,17 +175,14 @@ def _load_additional_themes(self, theme_paths: str) -> None:
174175
for name, theme in themes.items():
175176
self._themes[name] = theme
176177

177-
def _load_extra_theme(self, name: str) -> None:
178+
def _load_entry_point_themes(self) -> None:
178179
"""Try to load a theme with the specified name.
179180
180181
This uses the ``sphinx.html_themes`` entry point from package metadata.
181182
"""
182-
theme_entry_points = entry_points(group='sphinx.html_themes')
183-
try:
184-
entry_point = theme_entry_points[name]
185-
except KeyError:
186-
pass
187-
else:
183+
for entry_point in entry_points(group='sphinx.html_themes'):
184+
if entry_point.name in self._themes:
185+
continue # don't overwrite loaded themes
188186
self._app.registry.load_extension(self._app, entry_point.module)
189187
_config_post_init(self._app, self._app.config)
190188

@@ -219,9 +217,6 @@ def _find_themes(theme_path: str) -> dict[str, str]:
219217

220218
def create(self, name: str) -> Theme:
221219
"""Create an instance of theme."""
222-
if name not in self._themes:
223-
self._load_extra_theme(name)
224-
225220
if name not in self._themes:
226221
raise ThemeError(__('no theme named %r found (missing theme.toml?)') % name)
227222

0 commit comments

Comments
 (0)