@@ -159,6 +159,7 @@ def __init__(self, app: Sphinx) -> None:
159
159
self ._load_builtin_themes ()
160
160
if getattr (app .config , 'html_theme_path' , None ):
161
161
self ._load_additional_themes (app .config .html_theme_path )
162
+ self ._load_entry_point_themes ()
162
163
163
164
def _load_builtin_themes (self ) -> None :
164
165
"""Load built-in themes."""
@@ -174,17 +175,14 @@ def _load_additional_themes(self, theme_paths: str) -> None:
174
175
for name , theme in themes .items ():
175
176
self ._themes [name ] = theme
176
177
177
- def _load_extra_theme (self , name : str ) -> None :
178
+ def _load_entry_point_themes (self ) -> None :
178
179
"""Try to load a theme with the specified name.
179
180
180
181
This uses the ``sphinx.html_themes`` entry point from package metadata.
181
182
"""
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
188
186
self ._app .registry .load_extension (self ._app , entry_point .module )
189
187
_config_post_init (self ._app , self ._app .config )
190
188
@@ -219,9 +217,6 @@ def _find_themes(theme_path: str) -> dict[str, str]:
219
217
220
218
def create (self , name : str ) -> Theme :
221
219
"""Create an instance of theme."""
222
- if name not in self ._themes :
223
- self ._load_extra_theme (name )
224
-
225
220
if name not in self ._themes :
226
221
raise ThemeError (__ ('no theme named %r found (missing theme.toml?)' ) % name )
227
222
0 commit comments