From 26e3d66f5334a5aaff75bda030afe6dfa1cc94d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 28 Apr 2024 14:42:09 +0200 Subject: [PATCH] refactor: Log a warning when base templates are overridden Issue-151: https://github.com/mkdocstrings/python/issues/151 --- src/mkdocstrings_handlers/python/handler.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index fa8e384..0311100 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -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 @@ -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/