diff --git a/docs/_scripts/macros.py b/docs/_scripts/macros.py deleted file mode 100644 index 894aa49..0000000 --- a/docs/_scripts/macros.py +++ /dev/null @@ -1,81 +0,0 @@ -# License: MIT -# Copyright © 2024 Frequenz Energy-as-a-Service GmbH - -"""This module defines macros for use in Markdown files.""" - -from typing import Any - -import markdown as md -from markdown.extensions import toc -from mkdocs_macros import plugin as macros - -_CODE_ANNOTATION_MARKER: str = ( - r'' - r'' - r'' - r"" - r"" -) - - -def _slugify(text: str) -> str: - """Slugify a text. - - Args: - text: The text to slugify. - - Returns: - The slugified text. - """ - # The type of the return value is not defined for the markdown library. - # Also for some reason `mypy` thinks the `toc` module doesn't have a - # `slugify_unicode` function, but it definitely does. - return toc.slugify_unicode(text, "-") - - -def _hook_macros_plugin(env: macros.MacrosPlugin) -> None: - """Integrate the `mkdocs-macros` plugin into `mkdocstrings`. - - This is a temporary workaround to make `mkdocs-macros` work with - `mkdocstrings` until a proper `mkdocs-macros` *pluglet* is available. See - https://github.com/mkdocstrings/mkdocstrings/issues/615 for details. - - Args: - env: The environment to hook the plugin into. - """ - # get mkdocstrings' Python handler - python_handler = env.conf["plugins"]["mkdocstrings"].get_handler("python") - - # get the `update_env` method of the Python handler - update_env = python_handler.update_env - - # override the `update_env` method of the Python handler - def patched_update_env(markdown: md.Markdown, config: dict[str, Any]) -> None: - update_env(markdown, config) - - # get the `convert_markdown` filter of the env - convert_markdown = python_handler.env.filters["convert_markdown"] - - # build a chimera made of macros+mkdocstrings - def render_convert(markdown: str, *args: Any, **kwargs: Any) -> Any: - return convert_markdown(env.render(markdown), *args, **kwargs) - - # patch the filter - python_handler.env.filters["convert_markdown"] = render_convert - - # patch the method - python_handler.update_env = patched_update_env - - -def define_env(env: macros.MacrosPlugin) -> None: - """Define the hook to create macro functions for use in Markdown. - - Args: - env: The environment to define the macro functions in. - """ - # A variable to easily show an example code annotation from mkdocs-material. - # https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-annotations - env.variables["code_annotation_marker"] = _CODE_ANNOTATION_MARKER - - # This hook needs to be done at the end of the `define_env` function. - _hook_macros_plugin(env) diff --git a/mkdocs.yml b/mkdocs.yml index f4f76c9..cca1cd3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -115,10 +115,9 @@ plugins: - https://docs.python.org/3/objects.inv - https://typing-extensions.readthedocs.io/en/stable/objects.inv # Note this plugin must be loaded after mkdocstrings to be able to use macros - # inside docstrings. See the comment in `docs/_scripts/macros.py` for more - # details + # inside docstrings. - macros: - module_name: docs/_scripts/macros + modules: ["frequenz.repo.config.mkdocs.mkdocstrings_macros"] on_undefined: strict on_error_fail: true - search diff --git a/pyproject.toml b/pyproject.toml index afb0edb..403cee9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires = [ "setuptools == 75.8.0", "setuptools_scm[toml] == 8.1.0", - "frequenz-repo-config[lib] == 0.11.0", + "frequenz-repo-config[lib] == 0.12.3", ] build-backend = "setuptools.build_meta" @@ -32,7 +32,7 @@ dependencies = [ "frequenz-client-common >= 0.3.0, < 0.4", "grpcio >=1.66.1, < 2", "grpcio-tools >=1.66.1, < 2", - "protobuf >=5.28.2, < 6", + "protobuf >=5.28.3, < 6", "frequenz-client-base >= 0.8.0, < 0.10.0", ] dynamic = ["version"] @@ -61,8 +61,9 @@ dev-mkdocs = [ "mkdocs-literate-nav == 0.6.1", "mkdocs-macros-plugin == 1.3.7", "mkdocs-material == 9.6.1", - "mkdocstrings[python] == 0.27.0", - "frequenz-repo-config[lib] == 0.11.0", + "mkdocstrings[python] == 0.28.2", + "mkdocstrings-python == 1.16.2", + "frequenz-repo-config[lib] == 0.12.3", ] dev-mypy = [ "mypy == 1.14.1", @@ -74,7 +75,7 @@ dev-mypy = [ ] dev-noxfile = [ "nox == 2025.2.9", - "frequenz-repo-config[lib] == 0.11.0", + "frequenz-repo-config[lib] == 0.12.3", ] dev-pylint = [ "pylint == 3.3.4", @@ -84,7 +85,7 @@ dev-pylint = [ ] dev-pytest = [ "pytest == 8.3.4", - "frequenz-repo-config[extra-lint-examples] == 0.11.0", + "frequenz-repo-config[extra-lint-examples] == 0.12.3", "pytest-mock == 3.14.0", "pytest-asyncio == 0.25.3", "async-solipsism == 0.7", @@ -155,6 +156,7 @@ disable = [ ] [tool.pytest.ini_options] +addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv" testpaths = ["tests", "src"] asyncio_mode = "auto" asyncio_default_fixture_loop_scope = "function"