Skip to content

Commit f904312

Browse files
committed
Support loading existing mkdocs themes
Simply support the mkdocs.themes entrypoints but give preference to our entrypoints. Also, populate the mkdocs_version field for themes but with our project name prefix, to distinguish them if the theme renders this value.
1 parent f6bb5b9 commit f904312

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

docs/dev-guide/themes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ this can be used directly by prepending it to a local relative URL, it is best
315315
to use the [url](#url) template filter, which is smarter about how it applies
316316
`base_url`.
317317

318-
#### mkdocs_version
318+
#### properdocs_version
319319

320320
Contains the current ProperDocs version.
321321

properdocs/commands/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def get_context(
5151
base_url=base_url,
5252
extra_css=extra_css,
5353
extra_javascript=extra_javascript,
54-
mkdocs_version=properdocs.__version__,
54+
properdocs_version=properdocs.__version__,
55+
mkdocs_version=f"ProperDocs {properdocs.__version__}",
5556
build_date_utc=utils.get_build_datetime(),
5657
config=config,
5758
page=page,

properdocs/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_plugins() -> dict[str, EntryPoint]:
4949

5050
for prefix in pluginmaps:
5151
for plugin in entry_points(group=f'{prefix}.plugins'):
52-
if plugin.value.startswith('mkdocs.'):
52+
if getattr(plugin, 'value', '').startswith('mkdocs.'):
5353
continue
5454
# Allow third-party plugins to override core plugins
5555
if plugin.name in pluginmaps[prefix] and plugin.value.startswith(f"{prefix}.contrib."):

properdocs/tests/config/config_options_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,7 @@ class ThemePlugin2(BasePlugin[_FakePluginConfig]):
19391939
class FakeEntryPoint:
19401940
def __init__(self, name, cls):
19411941
self.name = name
1942+
self.value = 'properdocs'
19421943
self.cls = cls
19431944

19441945
def load(self):

properdocs/utils/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,21 @@ def get_theme_dir(name: str) -> str:
262262
@functools.lru_cache(maxsize=None)
263263
def get_themes() -> dict[str, EntryPoint]:
264264
"""Return a dict of all installed themes as {name: EntryPoint}."""
265-
themes: dict[str, EntryPoint] = {}
266-
eps: dict[EntryPoint, None] = dict.fromkeys(entry_points(group='properdocs.themes'))
267-
builtins = {ep.name for ep in eps if ep.dist is not None and ep.dist.name == 'properdocs'}
265+
# Ordered set of preferred entry points.
266+
eps: dict[EntryPoint, None] = {}
267+
builtins: set[str] = set()
268+
269+
for ep in entry_points(group='mkdocs.themes'):
270+
if ep.dist is not None and ep.dist.name != 'mkdocs':
271+
eps[ep] = None
272+
# These will get preference because they are later in the sequence:
273+
for ep in entry_points(group='properdocs.themes'):
274+
if ep.dist is not None:
275+
eps[ep] = None
276+
if ep.dist.name == 'properdocs':
277+
builtins.add(ep.name)
268278

279+
themes: dict[str, EntryPoint] = {}
269280
for theme in eps:
270281
assert theme.dist is not None
271282

properdocs/utils/templates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TemplateContext(TypedDict):
2828
base_url: str
2929
extra_css: Sequence[str] # Do not use, prefer `config.extra_css`.
3030
extra_javascript: Sequence[str] # Do not use, prefer `config.extra_javascript`.
31+
properdocs_version: str
3132
mkdocs_version: str
3233
build_date_utc: datetime.datetime
3334
config: ProperDocsConfig

0 commit comments

Comments
 (0)