diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fdbdf36..e1116c85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.10.1](https://github.com/mkdocstrings/python/releases/tag/1.10.1) - 2024-05-14 + +[Compare with 1.10.0](https://github.com/mkdocstrings/python/compare/1.10.0...1.10.1) + +### Build + +- Depend on mkdocstrings 0.25 which adds support for parameter `once` when logging messages ([2bc156b](https://github.com/mkdocstrings/python/commit/2bc156bd6f231ae13066651f4490d1e9c2ce3ca2) by Timothée Mazzucotelli). + +### Code Refactoring + +- Set handler's name ([a71ab12](https://github.com/mkdocstrings/python/commit/a71ab12c8e52efe76e5c0a5e54065926a47cc0d2) by Timothée Mazzucotelli). +- Update `*.html` top-level templates to extend the `*.html.jinja` base templates ([a8c540e](https://github.com/mkdocstrings/python/commit/a8c540e95693e8500da884c32ad159b3bbaaa7ba) by Timothée Mazzucotelli). [Issue-151](https://github.com/mkdocstrings/python/issues/151) +- Update `*.html` base templates to extend their `*.html.jinja` counterpart, while overriding the `logs` block to issue a logging message (info) stating that extending `*.html` templates is deprecated ([e6f1b9c](https://github.com/mkdocstrings/python/commit/e6f1b9caf13754eca9dbb2f112727bef50876ed7) by Timothée Mazzucotelli). [Issue-151](https://github.com/mkdocstrings/python/issues/151) +- Add `*.html.jinja` top-level (overridable) templates, extending their base counterpart ([7c14924](https://github.com/mkdocstrings/python/commit/7c14924c406d7b5f4f1c22d03019d4c566018d2d) by Timothée Mazzucotelli). [Issue-151](https://github.com/mkdocstrings/python/issues/151) +- Add `*.html.jinja` base templates, which are copies of `*.html` templates, with an additional `logs` block, and using the updated `get_template` filter ([eced9a5](https://github.com/mkdocstrings/python/commit/eced9a54fc8a559b686cb1b1180a0d2e04ba452d) by Timothée Mazzucotelli). [Issue-151](https://github.com/mkdocstrings/python/issues/151) +- Update `get_template` filter to support both `*.html` and `*.html.jinja` templates, logging a message (info) when `*.html` templates are overridden by users ([3546fd7](https://github.com/mkdocstrings/python/commit/3546fd70b2d4e45f77b166b2e67c333acc8af0d2) by Timothée Mazzucotelli). [Issue-151](https://github.com/mkdocstrings/python/issues/151) +- Log a warning when base templates are overridden ([26e3d66](https://github.com/mkdocstrings/python/commit/26e3d66f5334a5aaff75bda030afe6dfa1cc94d7) by Timothée Mazzucotelli). [Issue-151](https://github.com/mkdocstrings/python/issues/151) + ## [1.10.0](https://github.com/mkdocstrings/python/releases/tag/1.10.0) - 2024-04-19 [Compare with 1.9.2](https://github.com/mkdocstrings/python/compare/1.9.2...1.10.0) diff --git a/docs/usage/configuration/docstrings.md b/docs/usage/configuration/docstrings.md index fcb9a19a..dcb35f5e 100644 --- a/docs/usage/configuration/docstrings.md +++ b/docs/usage/configuration/docstrings.md @@ -120,7 +120,7 @@ class PrintOK: """Initialize the instance. Examples: - >>> Class() # doctest: +NORMALIZE_WHITESPACE + >>> PrintOK() # doctest: +NORMALIZE_WHITESPACE ok """ print("ok") @@ -136,7 +136,7 @@ class PrintOK:

Examples:

```pycon ->>> Class() +>>> PrintOK() ok ``` //// @@ -149,7 +149,7 @@ ok

Examples:

```pycon ->>> Class() # doctest: +NORMALIZE_WHITESPACE +>>> PrintOK() # doctest: +NORMALIZE_WHITESPACE ok ``` //// diff --git a/mkdocs.yml b/mkdocs.yml index 9a739787..631fbab9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -149,6 +149,7 @@ plugins: - https://docs.python.org/3/objects.inv - https://mkdocstrings.github.io/objects.inv - https://mkdocstrings.github.io/griffe/objects.inv + - https://python-markdown.github.io/objects.inv options: docstring_options: ignore_init_summary: true @@ -157,6 +158,7 @@ plugins: heading_level: 1 inherited_members: true merge_init_into_class: true + parameter_headings: true preload_modules: [mkdocstrings] separate_signature: true show_root_heading: true diff --git a/pyproject.toml b/pyproject.toml index c02461f1..398d5d3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "mkdocstrings>=0.24.2", + "mkdocstrings>=0.25", "griffe>=0.44", ] diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index fa8e384c..a473f92a 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 @@ -52,6 +53,8 @@ def chdir(path: str) -> Iterator[None]: # noqa: D103 class PythonHandler(BaseHandler): """The Python handler class.""" + name = "python" + """The handler's name.""" domain: str = "py" # to match Sphinx's default domain """The cross-documentation domain/language for this handler.""" enable_inventory: bool = True @@ -208,21 +211,42 @@ 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/