Skip to content

Commit

Permalink
refactor: Log a warning when base templates are overridden
Browse files Browse the repository at this point in the history
Issue-151: #151
  • Loading branch information
pawamoy committed Apr 28, 2024
1 parent 2bc156b commit 26e3d66
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
from collections import ChainMap
from contextlib import suppress
from pathlib import Path
from typing import TYPE_CHECKING, Any, BinaryIO, ClassVar, Iterator, Mapping, Sequence

from griffe.collections import LinesCollection, ModulesCollection
Expand Down Expand Up @@ -208,6 +209,17 @@ def __init__(
**kwargs: Same thing, but with keyword arguments.
"""
super().__init__(*args, **kwargs)

# Warn if user overrides base templates.
if custom_templates := kwargs.get("custom_templates", ()):
config_dir = Path(config_file_path or "./mkdocs.yml").parent
for theme_dir in config_dir.joinpath(custom_templates, "python").iterdir():
if theme_dir.joinpath("_base").is_dir():
logger.warning(
f"Overriding base template '{theme_dir.name}/_base/<template>.html.jinja' is not supported, "
f"override '{theme_dir.name}/<template>.html.jinja' instead",
)

self._config_file_path = config_file_path
self._load_external_modules = load_external_modules
paths = paths or []
Expand Down

0 comments on commit 26e3d66

Please sign in to comment.