Skip to content

Commit 5b30b0b

Browse files
committed
Migrate files to repo-config 0.12
Run the migration script from repo-config 0.12. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 27cf3b2 commit 5b30b0b

File tree

2 files changed

+8
-67
lines changed

2 files changed

+8
-67
lines changed

docs/_scripts/macros.py

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,18 @@
33

44
"""This module defines macros for use in Markdown files."""
55

6-
from typing import Any
7-
8-
import markdown as md
6+
from frequenz.repo.config.mkdocs.mkdocstrings_macros import hook_env_with_everything
97
from griffe import ModulesCollection, Object
10-
from markdown.extensions import toc
11-
from mkdocs_macros import plugin as macros
8+
from mkdocs_macros.plugin import MacrosPlugin
129
from mkdocstrings_handlers.python.handler import PythonHandler
1310

14-
_CODE_ANNOTATION_MARKER: str = (
15-
r'<span class="md-annotation">'
16-
r'<span class="md-annotation__index" tabindex="-1">'
17-
r'<span data-md-annotation-id="1"></span>'
18-
r"</span>"
19-
r"</span>"
20-
)
21-
22-
23-
def _slugify(text: str) -> str:
24-
"""Slugify a text.
25-
26-
Args:
27-
text: The text to slugify.
28-
29-
Returns:
30-
The slugified text.
31-
"""
32-
return toc.slugify_unicode(text, "-")
33-
34-
35-
def _hook_macros_plugin(env: macros.MacrosPlugin) -> None:
36-
"""Integrate the `mkdocs-macros` plugin into `mkdocstrings`.
37-
38-
This is a temporary workaround to make `mkdocs-macros` work with
39-
`mkdocstrings` until a proper `mkdocs-macros` *pluglet* is available. See
40-
https://github.com/mkdocstrings/mkdocstrings/issues/615 for details.
41-
42-
Args:
43-
env: The environment to hook the plugin into.
44-
"""
45-
# get mkdocstrings' Python handler
46-
python_handler = env.conf["plugins"]["mkdocstrings"].get_handler("python")
47-
48-
# get the `update_env` method of the Python handler
49-
update_env = python_handler.update_env
50-
51-
# override the `update_env` method of the Python handler
52-
def patched_update_env(markdown: md.Markdown, config: dict[str, Any]) -> None:
53-
update_env(markdown, config)
54-
55-
# get the `convert_markdown` filter of the env
56-
convert_markdown = python_handler.env.filters["convert_markdown"]
5711

58-
# build a chimera made of macros+mkdocstrings
59-
def render_convert(markdown: str, *args: Any, **kwargs: Any) -> Any:
60-
return convert_markdown(env.render(markdown), *args, **kwargs)
61-
62-
# patch the filter
63-
python_handler.env.filters["convert_markdown"] = render_convert
64-
65-
# patch the method
66-
python_handler.update_env = patched_update_env
67-
68-
69-
def define_env(env: macros.MacrosPlugin) -> None:
12+
def define_env(env: MacrosPlugin) -> None:
7013
"""Define the hook to create macro functions for use in Markdown.
7114
7215
Args:
7316
env: The environment to define the macro functions in.
7417
"""
75-
# A variable to easily show an example code annotation from mkdocs-material.
76-
# https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-annotations
77-
env.variables["code_annotation_marker"] = _CODE_ANNOTATION_MARKER
78-
7918
python_handler = env.conf["plugins"]["mkdocstrings"].get_handler("python")
8019
assert isinstance(python_handler, PythonHandler)
8120

@@ -108,9 +47,10 @@ def docstring_summary(symbol: str) -> str:
10847
"""
10948
docstring = _get_docstring(symbol)
11049
summary = docstring.splitlines(keepends=False)[0]
111-
return python_handler.do_convert_markdown(
50+
# The python_handler is untyped here, so ignore the type
51+
return python_handler.do_convert_markdown( # type: ignore[no-any-return]
11252
summary, heading_level=1, strip_paragraph=True
11353
)
11454

115-
# This hook needs to be done at the end of the `define_env` function.
116-
_hook_macros_plugin(env)
55+
# This must be at the end to enable all standard features
56+
hook_env_with_everything(env)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ disable = [
148148
]
149149

150150
[tool.pytest.ini_options]
151+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
151152
testpaths = ["tests", "src"]
152153
asyncio_mode = "auto"
153154
asyncio_default_fixture_loop_scope = "function"

0 commit comments

Comments
 (0)