mkdocstrings-python 1.9.2__py3-none-any.whl → 1.10.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mkdocstrings_handlers/python/handler.py +33 -3
- mkdocstrings_handlers/python/rendering.py +42 -8
- mkdocstrings_handlers/python/templates/material/_base/attribute.html +11 -80
- mkdocstrings_handlers/python/templates/material/_base/attribute.html.jinja +120 -0
- mkdocstrings_handlers/python/templates/material/_base/children.html +11 -154
- mkdocstrings_handlers/python/templates/material/_base/children.html.jinja +172 -0
- mkdocstrings_handlers/python/templates/material/_base/class.html +11 -142
- mkdocstrings_handlers/python/templates/material/_base/class.html.jinja +192 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/admonition.html +11 -5
- mkdocstrings_handlers/python/templates/material/_base/docstring/admonition.html.jinja +20 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/attributes.html +10 -89
- mkdocstrings_handlers/python/templates/material/_base/docstring/attributes.html.jinja +109 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/classes.html +10 -66
- mkdocstrings_handlers/python/templates/material/_base/docstring/classes.html.jinja +86 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/examples.html +10 -11
- mkdocstrings_handlers/python/templates/material/_base/docstring/examples.html.jinja +28 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/functions.html +10 -72
- mkdocstrings_handlers/python/templates/material/_base/docstring/functions.html.jinja +92 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/modules.html +10 -66
- mkdocstrings_handlers/python/templates/material/_base/docstring/modules.html.jinja +86 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/other_parameters.html +10 -89
- mkdocstrings_handlers/python/templates/material/_base/docstring/other_parameters.html.jinja +109 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html +10 -112
- mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html.jinja +132 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/raises.html +10 -82
- mkdocstrings_handlers/python/templates/material/_base/docstring/raises.html.jinja +102 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/receives.html +10 -102
- mkdocstrings_handlers/python/templates/material/_base/docstring/receives.html.jinja +122 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/returns.html +10 -102
- mkdocstrings_handlers/python/templates/material/_base/docstring/returns.html.jinja +122 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/warns.html +10 -82
- mkdocstrings_handlers/python/templates/material/_base/docstring/warns.html.jinja +102 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/yields.html +10 -102
- mkdocstrings_handlers/python/templates/material/_base/docstring/yields.html.jinja +122 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring.html +11 -34
- mkdocstrings_handlers/python/templates/material/_base/docstring.html.jinja +53 -0
- mkdocstrings_handlers/python/templates/material/_base/expression.html +10 -51
- mkdocstrings_handlers/python/templates/material/_base/expression.html.jinja +89 -0
- mkdocstrings_handlers/python/templates/material/_base/function.html +11 -98
- mkdocstrings_handlers/python/templates/material/_base/function.html.jinja +144 -0
- mkdocstrings_handlers/python/templates/material/_base/labels.html +11 -8
- mkdocstrings_handlers/python/templates/material/_base/labels.html.jinja +25 -0
- mkdocstrings_handlers/python/templates/material/_base/language.html +11 -0
- mkdocstrings_handlers/python/templates/material/_base/language.html.jinja +18 -0
- mkdocstrings_handlers/python/templates/material/_base/languages/en.html +11 -37
- mkdocstrings_handlers/python/templates/material/_base/languages/en.html.jinja +45 -0
- mkdocstrings_handlers/python/templates/material/_base/languages/ja.html +11 -37
- mkdocstrings_handlers/python/templates/material/_base/languages/ja.html.jinja +45 -0
- mkdocstrings_handlers/python/templates/material/_base/languages/zh.html +11 -37
- mkdocstrings_handlers/python/templates/material/_base/languages/zh.html.jinja +45 -0
- mkdocstrings_handlers/python/templates/material/_base/module.html +11 -74
- mkdocstrings_handlers/python/templates/material/_base/module.html.jinja +113 -0
- mkdocstrings_handlers/python/templates/material/_base/signature.html +11 -69
- mkdocstrings_handlers/python/templates/material/_base/signature.html.jinja +92 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/attributes.html +11 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/attributes.html.jinja +8 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/classes.html +11 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/classes.html.jinja +8 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/functions.html +11 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/functions.html.jinja +8 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/modules.html +11 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/modules.html.jinja +8 -0
- mkdocstrings_handlers/python/templates/material/_base/summary.html +11 -0
- mkdocstrings_handlers/python/templates/material/_base/summary.html.jinja +8 -0
- mkdocstrings_handlers/python/templates/material/attribute.html +1 -1
- mkdocstrings_handlers/python/templates/material/attribute.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/children.html +1 -1
- mkdocstrings_handlers/python/templates/material/children.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/class.html +1 -1
- mkdocstrings_handlers/python/templates/material/class.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/admonition.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/admonition.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/attributes.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/attributes.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/classes.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/classes.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/examples.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/examples.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/functions.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/functions.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/modules.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/modules.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/other_parameters.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/other_parameters.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/parameters.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/parameters.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/raises.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/raises.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/receives.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/receives.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/returns.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/returns.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/warns.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/warns.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/yields.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring/yields.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring.html +1 -1
- mkdocstrings_handlers/python/templates/material/docstring.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/expression.html +1 -1
- mkdocstrings_handlers/python/templates/material/expression.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/function.html +1 -1
- mkdocstrings_handlers/python/templates/material/function.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/labels.html +1 -1
- mkdocstrings_handlers/python/templates/material/labels.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/language.html +1 -10
- mkdocstrings_handlers/python/templates/material/language.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/languages/en.html +1 -1
- mkdocstrings_handlers/python/templates/material/languages/en.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/languages/ja.html +1 -1
- mkdocstrings_handlers/python/templates/material/languages/ja.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/languages/zh.html +1 -1
- mkdocstrings_handlers/python/templates/material/languages/zh.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/module.html +1 -1
- mkdocstrings_handlers/python/templates/material/module.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/signature.html +1 -1
- mkdocstrings_handlers/python/templates/material/signature.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/style.css +5 -0
- mkdocstrings_handlers/python/templates/material/summary/attributes.html +1 -1
- mkdocstrings_handlers/python/templates/material/summary/attributes.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/summary/classes.html +1 -1
- mkdocstrings_handlers/python/templates/material/summary/classes.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/summary/functions.html +1 -1
- mkdocstrings_handlers/python/templates/material/summary/functions.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/summary/modules.html +1 -1
- mkdocstrings_handlers/python/templates/material/summary/modules.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/summary.html +1 -1
- mkdocstrings_handlers/python/templates/material/summary.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/attributes.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/attributes.html.jinja +49 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/other_parameters.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/other_parameters.html.jinja +49 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/parameters.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/parameters.html.jinja +54 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/raises.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/raises.html.jinja +48 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/receives.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/receives.html.jinja +51 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/returns.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/returns.html.jinja +51 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/warns.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/warns.html.jinja +48 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/yields.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/yields.html.jinja +51 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/language.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/language.html.jinja +18 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/languages/en.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/languages/en.html.jinja +39 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/languages/ja.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/languages/ja.html.jinja +39 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/languages/zh.html +11 -0
- mkdocstrings_handlers/python/templates/readthedocs/_base/languages/zh.html.jinja +39 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/attributes.html +1 -33
- mkdocstrings_handlers/python/templates/readthedocs/docstring/attributes.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/other_parameters.html +1 -33
- mkdocstrings_handlers/python/templates/readthedocs/docstring/other_parameters.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/parameters.html +1 -38
- mkdocstrings_handlers/python/templates/readthedocs/docstring/parameters.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/raises.html +1 -32
- mkdocstrings_handlers/python/templates/readthedocs/docstring/raises.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/receives.html +1 -35
- mkdocstrings_handlers/python/templates/readthedocs/docstring/receives.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/returns.html +1 -35
- mkdocstrings_handlers/python/templates/readthedocs/docstring/returns.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/warns.html +1 -32
- mkdocstrings_handlers/python/templates/readthedocs/docstring/warns.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/docstring/yields.html +1 -35
- mkdocstrings_handlers/python/templates/readthedocs/docstring/yields.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/language.html +1 -10
- mkdocstrings_handlers/python/templates/readthedocs/language.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/languages/en.html +1 -37
- mkdocstrings_handlers/python/templates/readthedocs/languages/en.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/languages/ja.html +1 -37
- mkdocstrings_handlers/python/templates/readthedocs/languages/ja.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/readthedocs/languages/zh.html +1 -37
- mkdocstrings_handlers/python/templates/readthedocs/languages/zh.html.jinja +1 -0
- {mkdocstrings_python-1.9.2.dist-info → mkdocstrings_python-1.10.1.dist-info}/METADATA +4 -4
- mkdocstrings_python-1.10.1.dist-info/RECORD +183 -0
- {mkdocstrings_python-1.9.2.dist-info → mkdocstrings_python-1.10.1.dist-info}/WHEEL +1 -1
- mkdocstrings_python-1.9.2.dist-info/RECORD +0 -84
- {mkdocstrings_python-1.9.2.dist-info → mkdocstrings_python-1.10.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -9,6 +9,7 @@ import re
|
|
|
9
9
|
import sys
|
|
10
10
|
from collections import ChainMap
|
|
11
11
|
from contextlib import suppress
|
|
12
|
+
from pathlib import Path
|
|
12
13
|
from typing import TYPE_CHECKING, Any, BinaryIO, ClassVar, Iterator, Mapping, Sequence
|
|
13
14
|
|
|
14
15
|
from griffe.collections import LinesCollection, ModulesCollection
|
|
@@ -52,6 +53,8 @@ patch_loggers(get_logger)
|
|
|
52
53
|
class PythonHandler(BaseHandler):
|
|
53
54
|
"""The Python handler class."""
|
|
54
55
|
|
|
56
|
+
name = "python"
|
|
57
|
+
"""The handler's name."""
|
|
55
58
|
domain: str = "py" # to match Sphinx's default domain
|
|
56
59
|
"""The cross-documentation domain/language for this handler."""
|
|
57
60
|
enable_inventory: bool = True
|
|
@@ -208,21 +211,42 @@ class PythonHandler(BaseHandler):
|
|
|
208
211
|
**kwargs: Same thing, but with keyword arguments.
|
|
209
212
|
"""
|
|
210
213
|
super().__init__(*args, **kwargs)
|
|
214
|
+
|
|
215
|
+
# Warn if user overrides base templates.
|
|
216
|
+
if custom_templates := kwargs.get("custom_templates", ()):
|
|
217
|
+
config_dir = Path(config_file_path or "./mkdocs.yml").parent
|
|
218
|
+
for theme_dir in config_dir.joinpath(custom_templates, "python").iterdir():
|
|
219
|
+
if theme_dir.joinpath("_base").is_dir():
|
|
220
|
+
logger.warning(
|
|
221
|
+
f"Overriding base template '{theme_dir.name}/_base/<template>.html.jinja' is not supported, "
|
|
222
|
+
f"override '{theme_dir.name}/<template>.html.jinja' instead",
|
|
223
|
+
)
|
|
224
|
+
|
|
211
225
|
self._config_file_path = config_file_path
|
|
212
226
|
self._load_external_modules = load_external_modules
|
|
213
227
|
paths = paths or []
|
|
228
|
+
|
|
229
|
+
# Expand paths with glob patterns.
|
|
214
230
|
glob_base_dir = os.path.dirname(os.path.abspath(config_file_path)) if config_file_path else "."
|
|
215
231
|
with chdir(glob_base_dir):
|
|
216
232
|
resolved_globs = [glob.glob(path) for path in paths]
|
|
217
233
|
paths = [path for glob_list in resolved_globs for path in glob_list]
|
|
234
|
+
|
|
235
|
+
# By default, add the directory of the config file to the search paths.
|
|
218
236
|
if not paths and config_file_path:
|
|
219
237
|
paths.append(os.path.dirname(config_file_path))
|
|
220
|
-
|
|
238
|
+
|
|
239
|
+
# Initialize search paths from `sys.path`, eliminating empty paths.
|
|
240
|
+
search_paths = [path for path in sys.path if path]
|
|
241
|
+
|
|
221
242
|
for path in reversed(paths):
|
|
243
|
+
# If it's not absolute, make path relative to the config file path, then make it absolute.
|
|
222
244
|
if not os.path.isabs(path) and config_file_path:
|
|
223
245
|
path = os.path.abspath(os.path.join(os.path.dirname(config_file_path), path)) # noqa: PLW2901
|
|
246
|
+
# Don't add duplicates.
|
|
224
247
|
if path not in search_paths:
|
|
225
248
|
search_paths.insert(0, path)
|
|
249
|
+
|
|
226
250
|
self._paths = search_paths
|
|
227
251
|
self._modules_collection: ModulesCollection = ModulesCollection()
|
|
228
252
|
self._lines_collection: LinesCollection = LinesCollection()
|
|
@@ -321,7 +345,7 @@ class PythonHandler(BaseHandler):
|
|
|
321
345
|
def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa: D102 (ignore missing docstring)
|
|
322
346
|
final_config = ChainMap(config, self.default_config) # type: ignore[arg-type]
|
|
323
347
|
|
|
324
|
-
template_name = rendering.do_get_template(data)
|
|
348
|
+
template_name = rendering.do_get_template(self.env, data)
|
|
325
349
|
template = self.env.get_template(template_name)
|
|
326
350
|
|
|
327
351
|
# Heading level is a "state" variable, that will change at each step
|
|
@@ -374,7 +398,13 @@ class PythonHandler(BaseHandler):
|
|
|
374
398
|
},
|
|
375
399
|
)
|
|
376
400
|
|
|
377
|
-
def update_env(self, md: Markdown, config: dict) -> None:
|
|
401
|
+
def update_env(self, md: Markdown, config: dict) -> None:
|
|
402
|
+
"""Update the Jinja environment with custom filters and tests.
|
|
403
|
+
|
|
404
|
+
Parameters:
|
|
405
|
+
md: The Markdown instance.
|
|
406
|
+
config: The configuration dictionary.
|
|
407
|
+
"""
|
|
378
408
|
super().update_env(md, config)
|
|
379
409
|
self.env.trim_blocks = True
|
|
380
410
|
self.env.lstrip_blocks = True
|
|
@@ -9,20 +9,23 @@ import string
|
|
|
9
9
|
import sys
|
|
10
10
|
import warnings
|
|
11
11
|
from functools import lru_cache, partial
|
|
12
|
+
from pathlib import Path
|
|
12
13
|
from typing import TYPE_CHECKING, Any, Callable, Match, Pattern, Sequence
|
|
13
14
|
|
|
15
|
+
from griffe.dataclasses import Alias, Object
|
|
14
16
|
from griffe.docstrings.dataclasses import (
|
|
15
17
|
DocstringSectionAttributes,
|
|
16
18
|
DocstringSectionClasses,
|
|
17
19
|
DocstringSectionFunctions,
|
|
18
20
|
DocstringSectionModules,
|
|
19
21
|
)
|
|
20
|
-
from jinja2 import pass_context
|
|
22
|
+
from jinja2 import TemplateNotFound, pass_context, pass_environment
|
|
21
23
|
from markupsafe import Markup
|
|
22
24
|
from mkdocstrings.loggers import get_logger
|
|
23
25
|
|
|
24
26
|
if TYPE_CHECKING:
|
|
25
|
-
from griffe.dataclasses import
|
|
27
|
+
from griffe.dataclasses import Attribute, Class, Function, Module
|
|
28
|
+
from jinja2 import Environment, Template
|
|
26
29
|
from jinja2.runtime import Context
|
|
27
30
|
from mkdocstrings.handlers.base import CollectorItem
|
|
28
31
|
|
|
@@ -137,7 +140,8 @@ def do_format_signature(
|
|
|
137
140
|
The same code, formatted.
|
|
138
141
|
"""
|
|
139
142
|
env = context.environment
|
|
140
|
-
|
|
143
|
+
# TODO: Stop using `do_get_template` when `*.html` templates are removed.
|
|
144
|
+
template = env.get_template(do_get_template(env, "signature"))
|
|
141
145
|
config_annotations = context.parent["config"]["show_signature_annotations"]
|
|
142
146
|
old_stash_ref_filter = env.filters["stash_crossref"]
|
|
143
147
|
|
|
@@ -204,7 +208,8 @@ def do_format_attribute(
|
|
|
204
208
|
The same code, formatted.
|
|
205
209
|
"""
|
|
206
210
|
env = context.environment
|
|
207
|
-
|
|
211
|
+
# TODO: Stop using `do_get_template` when `*.html` templates are removed.
|
|
212
|
+
template = env.get_template(do_get_template(env, "expression"))
|
|
208
213
|
annotations = context.parent["config"]["show_signature_annotations"]
|
|
209
214
|
separate_signature = context.parent["config"]["separate_signature"]
|
|
210
215
|
old_stash_ref_filter = env.filters["stash_crossref"]
|
|
@@ -448,17 +453,46 @@ def _get_black_formatter() -> Callable[[str, int], str]:
|
|
|
448
453
|
return formatter
|
|
449
454
|
|
|
450
455
|
|
|
451
|
-
|
|
456
|
+
@pass_environment
|
|
457
|
+
def do_get_template(env: Environment, obj: str | Object) -> str | Template:
|
|
452
458
|
"""Get the template name used to render an object.
|
|
453
459
|
|
|
454
460
|
Parameters:
|
|
455
|
-
|
|
461
|
+
env: The Jinja environment, passed automatically.
|
|
462
|
+
obj: A Griffe object, or a template name.
|
|
456
463
|
|
|
457
464
|
Returns:
|
|
458
465
|
A template name.
|
|
459
466
|
"""
|
|
460
|
-
|
|
461
|
-
|
|
467
|
+
name = obj
|
|
468
|
+
if isinstance(obj, (Alias, Object)):
|
|
469
|
+
extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {})
|
|
470
|
+
if name := extra_data.get("template", ""):
|
|
471
|
+
return name
|
|
472
|
+
name = obj.kind.value
|
|
473
|
+
try:
|
|
474
|
+
template = env.get_template(f"{name}.html")
|
|
475
|
+
except TemplateNotFound:
|
|
476
|
+
return f"{name}.html.jinja"
|
|
477
|
+
else:
|
|
478
|
+
# TODO: Remove once support for Python 3.8 is dropped.
|
|
479
|
+
if sys.version_info < (3, 9):
|
|
480
|
+
try:
|
|
481
|
+
Path(template.filename).relative_to(Path(__file__).parent) # type: ignore[arg-type]
|
|
482
|
+
except ValueError:
|
|
483
|
+
our_template = False
|
|
484
|
+
else:
|
|
485
|
+
our_template = True
|
|
486
|
+
else:
|
|
487
|
+
our_template = Path(template.filename).is_relative_to(Path(__file__).parent) # type: ignore[arg-type]
|
|
488
|
+
if not our_template:
|
|
489
|
+
# TODO: Switch to a warning log after some time.
|
|
490
|
+
logger.info(
|
|
491
|
+
f"DeprecationWarning: Overriding '{name}.html' is deprecated, override '{name}.html.jinja' instead. "
|
|
492
|
+
"After some time, this message will be logged as a warning, causing strict builds to fail.",
|
|
493
|
+
once=True,
|
|
494
|
+
)
|
|
495
|
+
return f"{name}.html"
|
|
462
496
|
|
|
463
497
|
|
|
464
498
|
@pass_context
|
|
@@ -1,80 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
{
|
|
5
|
-
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{% else %}
|
|
13
|
-
{% set show_full_path = config.show_object_full_path %}
|
|
14
|
-
{% endif %}
|
|
15
|
-
|
|
16
|
-
{% set attribute_name = attribute.path if show_full_path else attribute.name %}
|
|
17
|
-
|
|
18
|
-
{% if not root or config.show_root_heading %}
|
|
19
|
-
{% filter heading(
|
|
20
|
-
heading_level,
|
|
21
|
-
role="data" if attribute.parent.kind.value == "module" else "attr",
|
|
22
|
-
id=html_id,
|
|
23
|
-
class="doc doc-heading",
|
|
24
|
-
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + attribute.name,
|
|
25
|
-
) %}
|
|
26
|
-
|
|
27
|
-
{% block heading scoped %}
|
|
28
|
-
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-attribute"></code>{% endif %}
|
|
29
|
-
{% if config.separate_signature %}
|
|
30
|
-
<span class="doc doc-object-name doc-attribute-name">{{ attribute_name }}</span>
|
|
31
|
-
{% else %}
|
|
32
|
-
{%+ filter highlight(language="python", inline=True) %}
|
|
33
|
-
{{ attribute_name }}{% if attribute.annotation %}: {{ attribute.annotation }}{% endif %}
|
|
34
|
-
{% if attribute.value %} = {{ attribute.value }}{% endif %}
|
|
35
|
-
{% endfilter %}
|
|
36
|
-
{% endif %}
|
|
37
|
-
{% endblock heading %}
|
|
38
|
-
|
|
39
|
-
{% block labels scoped %}
|
|
40
|
-
{% with labels = attribute.labels %}
|
|
41
|
-
{% include "labels.html" with context %}
|
|
42
|
-
{% endwith %}
|
|
43
|
-
{% endblock labels %}
|
|
44
|
-
|
|
45
|
-
{% endfilter %}
|
|
46
|
-
|
|
47
|
-
{% block signature scoped %}
|
|
48
|
-
{% if config.separate_signature %}
|
|
49
|
-
{% filter format_attribute(attribute, config.line_length, crossrefs=config.signature_crossrefs) %}
|
|
50
|
-
{{ attribute.name }}
|
|
51
|
-
{% endfilter %}
|
|
52
|
-
{% endif %}
|
|
53
|
-
{% endblock signature %}
|
|
54
|
-
|
|
55
|
-
{% else %}
|
|
56
|
-
|
|
57
|
-
{% if config.show_root_toc_entry %}
|
|
58
|
-
{% filter heading(heading_level,
|
|
59
|
-
role="data" if attribute.parent.kind.value == "module" else "attr",
|
|
60
|
-
id=html_id,
|
|
61
|
-
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + attribute.name,
|
|
62
|
-
hidden=True,
|
|
63
|
-
) %}
|
|
64
|
-
{% endfilter %}
|
|
65
|
-
{% endif %}
|
|
66
|
-
{% set heading_level = heading_level - 1 %}
|
|
67
|
-
{% endif %}
|
|
68
|
-
|
|
69
|
-
<div class="doc doc-contents {% if root %}first{% endif %}">
|
|
70
|
-
{% block contents scoped %}
|
|
71
|
-
{% block docstring scoped %}
|
|
72
|
-
{% with docstring_sections = attribute.docstring.parsed %}
|
|
73
|
-
{% include "docstring.html" with context %}
|
|
74
|
-
{% endwith %}
|
|
75
|
-
{% endblock docstring %}
|
|
76
|
-
{% endblock contents %}
|
|
77
|
-
</div>
|
|
78
|
-
|
|
79
|
-
{% endwith %}
|
|
80
|
-
</div>
|
|
1
|
+
{% extends "_base/attribute.html.jinja" %}
|
|
2
|
+
|
|
3
|
+
{% block logs scoped %}
|
|
4
|
+
{{ super() }}
|
|
5
|
+
{# TODO: Switch to a warning after some time. #}
|
|
6
|
+
{{ log.info(
|
|
7
|
+
"DeprecationWarning: Extending '_base/attribute.html' is deprecated, extend '_base/attribute.html.jinja' instead. " ~
|
|
8
|
+
"After some time, this message will be logged as a warning, causing strict builds to fail.",
|
|
9
|
+
once=True,
|
|
10
|
+
) }}
|
|
11
|
+
{% endblock logs %}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
{#- Template for Python attributes.
|
|
2
|
+
|
|
3
|
+
This template renders a Python attribute (or variable).
|
|
4
|
+
This can be a module attribute or a class attribute.
|
|
5
|
+
|
|
6
|
+
Context:
|
|
7
|
+
attribute (griffe.dataclasses.Attribute): The attribute to render.
|
|
8
|
+
root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
|
|
9
|
+
heading_level (int): The HTML heading level to use.
|
|
10
|
+
config (dict): The configuration options.
|
|
11
|
+
-#}
|
|
12
|
+
|
|
13
|
+
{% block logs scoped %}
|
|
14
|
+
{#- Logging block.
|
|
15
|
+
|
|
16
|
+
This block can be used to log debug messages, deprecation messages, warnings, etc.
|
|
17
|
+
-#}
|
|
18
|
+
{{ log.debug("Rendering " + attribute.path) }}
|
|
19
|
+
{% endblock logs %}
|
|
20
|
+
|
|
21
|
+
<div class="doc doc-object doc-attribute">
|
|
22
|
+
{% with obj = attribute, html_id = attribute.path %}
|
|
23
|
+
|
|
24
|
+
{% if root %}
|
|
25
|
+
{% set show_full_path = config.show_root_full_path %}
|
|
26
|
+
{% set root_members = True %}
|
|
27
|
+
{% elif root_members %}
|
|
28
|
+
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
|
|
29
|
+
{% set root_members = False %}
|
|
30
|
+
{% else %}
|
|
31
|
+
{% set show_full_path = config.show_object_full_path %}
|
|
32
|
+
{% endif %}
|
|
33
|
+
|
|
34
|
+
{% set attribute_name = attribute.path if show_full_path else attribute.name %}
|
|
35
|
+
|
|
36
|
+
{% if not root or config.show_root_heading %}
|
|
37
|
+
{% filter heading(
|
|
38
|
+
heading_level,
|
|
39
|
+
role="data" if attribute.parent.kind.value == "module" else "attr",
|
|
40
|
+
id=html_id,
|
|
41
|
+
class="doc doc-heading",
|
|
42
|
+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + attribute.name,
|
|
43
|
+
) %}
|
|
44
|
+
|
|
45
|
+
{% block heading scoped %}
|
|
46
|
+
{#- Heading block.
|
|
47
|
+
|
|
48
|
+
This block renders the heading for the attribute.
|
|
49
|
+
-#}
|
|
50
|
+
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-attribute"></code>{% endif %}
|
|
51
|
+
{% if config.separate_signature %}
|
|
52
|
+
<span class="doc doc-object-name doc-attribute-name">{{ attribute_name }}</span>
|
|
53
|
+
{% else %}
|
|
54
|
+
{%+ filter highlight(language="python", inline=True) %}
|
|
55
|
+
{{ attribute_name }}{% if attribute.annotation %}: {{ attribute.annotation }}{% endif %}
|
|
56
|
+
{% if attribute.value %} = {{ attribute.value }}{% endif %}
|
|
57
|
+
{% endfilter %}
|
|
58
|
+
{% endif %}
|
|
59
|
+
{% endblock heading %}
|
|
60
|
+
|
|
61
|
+
{% block labels scoped %}
|
|
62
|
+
{#- Labels block.
|
|
63
|
+
|
|
64
|
+
This block renders the labels for the attribute.
|
|
65
|
+
-#}
|
|
66
|
+
{% with labels = attribute.labels %}
|
|
67
|
+
{% include "labels"|get_template with context %}
|
|
68
|
+
{% endwith %}
|
|
69
|
+
{% endblock labels %}
|
|
70
|
+
|
|
71
|
+
{% endfilter %}
|
|
72
|
+
|
|
73
|
+
{% block signature scoped %}
|
|
74
|
+
{#- Signature block.
|
|
75
|
+
|
|
76
|
+
This block renders the signature for the attribute.
|
|
77
|
+
-#}
|
|
78
|
+
{% if config.separate_signature %}
|
|
79
|
+
{% filter format_attribute(attribute, config.line_length, crossrefs=config.signature_crossrefs) %}
|
|
80
|
+
{{ attribute.name }}
|
|
81
|
+
{% endfilter %}
|
|
82
|
+
{% endif %}
|
|
83
|
+
{% endblock signature %}
|
|
84
|
+
|
|
85
|
+
{% else %}
|
|
86
|
+
|
|
87
|
+
{% if config.show_root_toc_entry %}
|
|
88
|
+
{% filter heading(heading_level,
|
|
89
|
+
role="data" if attribute.parent.kind.value == "module" else "attr",
|
|
90
|
+
id=html_id,
|
|
91
|
+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + attribute.name,
|
|
92
|
+
hidden=True,
|
|
93
|
+
) %}
|
|
94
|
+
{% endfilter %}
|
|
95
|
+
{% endif %}
|
|
96
|
+
{% set heading_level = heading_level - 1 %}
|
|
97
|
+
{% endif %}
|
|
98
|
+
|
|
99
|
+
<div class="doc doc-contents {% if root %}first{% endif %}">
|
|
100
|
+
{% block contents scoped %}
|
|
101
|
+
{#- Contents block.
|
|
102
|
+
|
|
103
|
+
This block renders the contents of the attribute.
|
|
104
|
+
It contains other blocks that users can override.
|
|
105
|
+
Overriding the contents block allows to rearrange the order of the blocks.
|
|
106
|
+
-#}
|
|
107
|
+
{% block docstring scoped %}
|
|
108
|
+
{#- Docstring block.
|
|
109
|
+
|
|
110
|
+
This block renders the docstring for the attribute.
|
|
111
|
+
-#}
|
|
112
|
+
{% with docstring_sections = attribute.docstring.parsed %}
|
|
113
|
+
{% include "docstring"|get_template with context %}
|
|
114
|
+
{% endwith %}
|
|
115
|
+
{% endblock docstring %}
|
|
116
|
+
{% endblock contents %}
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
{% endwith %}
|
|
120
|
+
</div>
|
|
@@ -1,154 +1,11 @@
|
|
|
1
|
-
{%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{% if config.group_by_category %}
|
|
13
|
-
|
|
14
|
-
{% with %}
|
|
15
|
-
|
|
16
|
-
{% if config.show_category_heading %}
|
|
17
|
-
{% set extra_level = 1 %}
|
|
18
|
-
{% else %}
|
|
19
|
-
{% set extra_level = 0 %}
|
|
20
|
-
{% endif %}
|
|
21
|
-
|
|
22
|
-
{% with attributes = obj.attributes|filter_objects(
|
|
23
|
-
filters=config.filters,
|
|
24
|
-
members_list=members_list,
|
|
25
|
-
inherited_members=config.inherited_members,
|
|
26
|
-
keep_no_docstrings=config.show_if_no_docstring,
|
|
27
|
-
) %}
|
|
28
|
-
{% if attributes %}
|
|
29
|
-
{% if config.show_category_heading %}
|
|
30
|
-
{% filter heading(heading_level, id=html_id ~ "-attributes") %}Attributes{% endfilter %}
|
|
31
|
-
{% endif %}
|
|
32
|
-
{% with heading_level = heading_level + extra_level %}
|
|
33
|
-
{% for attribute in attributes|order_members(config.members_order, members_list) %}
|
|
34
|
-
{% if members_list is not none or attribute.is_public(check_name=False) %}
|
|
35
|
-
{% include attribute|get_template with context %}
|
|
36
|
-
{% endif %}
|
|
37
|
-
{% endfor %}
|
|
38
|
-
{% endwith %}
|
|
39
|
-
{% endif %}
|
|
40
|
-
{% endwith %}
|
|
41
|
-
|
|
42
|
-
{% with classes = obj.classes|filter_objects(
|
|
43
|
-
filters=config.filters,
|
|
44
|
-
members_list=members_list,
|
|
45
|
-
inherited_members=config.inherited_members,
|
|
46
|
-
keep_no_docstrings=config.show_if_no_docstring,
|
|
47
|
-
) %}
|
|
48
|
-
{% if classes %}
|
|
49
|
-
{% if config.show_category_heading %}
|
|
50
|
-
{% filter heading(heading_level, id=html_id ~ "-classes") %}Classes{% endfilter %}
|
|
51
|
-
{% endif %}
|
|
52
|
-
{% with heading_level = heading_level + extra_level %}
|
|
53
|
-
{% for class in classes|order_members(config.members_order, members_list) %}
|
|
54
|
-
{% if members_list is not none or class.is_public(check_name=False) %}
|
|
55
|
-
{% include class|get_template with context %}
|
|
56
|
-
{% endif %}
|
|
57
|
-
{% endfor %}
|
|
58
|
-
{% endwith %}
|
|
59
|
-
{% endif %}
|
|
60
|
-
{% endwith %}
|
|
61
|
-
|
|
62
|
-
{% with functions = obj.functions|filter_objects(
|
|
63
|
-
filters=config.filters,
|
|
64
|
-
members_list=members_list,
|
|
65
|
-
inherited_members=config.inherited_members,
|
|
66
|
-
keep_no_docstrings=config.show_if_no_docstring,
|
|
67
|
-
) %}
|
|
68
|
-
{% if functions %}
|
|
69
|
-
{% if config.show_category_heading %}
|
|
70
|
-
{% filter heading(heading_level, id=html_id ~ "-functions") %}Functions{% endfilter %}
|
|
71
|
-
{% endif %}
|
|
72
|
-
{% with heading_level = heading_level + extra_level %}
|
|
73
|
-
{% for function in functions|order_members(config.members_order, members_list) %}
|
|
74
|
-
{% if not (obj.kind.value == "class" and function.name == "__init__" and config.merge_init_into_class) %}
|
|
75
|
-
{% if members_list is not none or function.is_public(check_name=False) %}
|
|
76
|
-
{% include function|get_template with context %}
|
|
77
|
-
{% endif %}
|
|
78
|
-
{% endif %}
|
|
79
|
-
{% endfor %}
|
|
80
|
-
{% endwith %}
|
|
81
|
-
{% endif %}
|
|
82
|
-
{% endwith %}
|
|
83
|
-
|
|
84
|
-
{% if config.show_submodules %}
|
|
85
|
-
{% with modules = obj.modules|filter_objects(
|
|
86
|
-
filters=config.filters,
|
|
87
|
-
members_list=members_list,
|
|
88
|
-
inherited_members=config.inherited_members,
|
|
89
|
-
keep_no_docstrings=config.show_if_no_docstring,
|
|
90
|
-
) %}
|
|
91
|
-
{% if modules %}
|
|
92
|
-
{% if config.show_category_heading %}
|
|
93
|
-
{% filter heading(heading_level, id=html_id ~ "-modules") %}Modules{% endfilter %}
|
|
94
|
-
{% endif %}
|
|
95
|
-
{% with heading_level = heading_level + extra_level %}
|
|
96
|
-
{% for module in modules|order_members(config.members_order.alphabetical, members_list) %}
|
|
97
|
-
{% if members_list is not none or module.is_public(check_name=False) %}
|
|
98
|
-
{% include module|get_template with context %}
|
|
99
|
-
{% endif %}
|
|
100
|
-
{% endfor %}
|
|
101
|
-
{% endwith %}
|
|
102
|
-
{% endif %}
|
|
103
|
-
{% endwith %}
|
|
104
|
-
{% endif %}
|
|
105
|
-
|
|
106
|
-
{% endwith %}
|
|
107
|
-
|
|
108
|
-
{% else %}
|
|
109
|
-
|
|
110
|
-
{% for child in obj.all_members
|
|
111
|
-
|filter_objects(
|
|
112
|
-
filters=config.filters,
|
|
113
|
-
members_list=members_list,
|
|
114
|
-
inherited_members=config.inherited_members,
|
|
115
|
-
keep_no_docstrings=config.show_if_no_docstring,
|
|
116
|
-
)
|
|
117
|
-
|order_members(config.members_order, members_list)
|
|
118
|
-
%}
|
|
119
|
-
|
|
120
|
-
{% if not (obj.is_class and child.name == "__init__" and config.merge_init_into_class) %}
|
|
121
|
-
|
|
122
|
-
{% if members_list is not none or child.is_public(check_name=False) %}
|
|
123
|
-
{% if child.is_attribute %}
|
|
124
|
-
{% with attribute = child %}
|
|
125
|
-
{% include attribute|get_template with context %}
|
|
126
|
-
{% endwith %}
|
|
127
|
-
|
|
128
|
-
{% elif child.is_class %}
|
|
129
|
-
{% with class = child %}
|
|
130
|
-
{% include class|get_template with context %}
|
|
131
|
-
{% endwith %}
|
|
132
|
-
|
|
133
|
-
{% elif child.is_function %}
|
|
134
|
-
{% with function = child %}
|
|
135
|
-
{% include function|get_template with context %}
|
|
136
|
-
{% endwith %}
|
|
137
|
-
|
|
138
|
-
{% elif child.is_module and config.show_submodules %}
|
|
139
|
-
{% with module = child %}
|
|
140
|
-
{% include module|get_template with context %}
|
|
141
|
-
{% endwith %}
|
|
142
|
-
|
|
143
|
-
{% endif %}
|
|
144
|
-
{% endif %}
|
|
145
|
-
|
|
146
|
-
{% endif %}
|
|
147
|
-
|
|
148
|
-
{% endfor %}
|
|
149
|
-
|
|
150
|
-
{% endif %}
|
|
151
|
-
|
|
152
|
-
</div>
|
|
153
|
-
|
|
154
|
-
{% endif %}
|
|
1
|
+
{% extends "_base/children.html.jinja" %}
|
|
2
|
+
|
|
3
|
+
{% block logs scoped %}
|
|
4
|
+
{{ super() }}
|
|
5
|
+
{# TODO: Switch to a warning after some time. #}
|
|
6
|
+
{{ log.info(
|
|
7
|
+
"DeprecationWarning: Extending '_base/children.html' is deprecated, extend '_base/children.html.jinja' instead. " ~
|
|
8
|
+
"After some time, this message will be logged as a warning, causing strict builds to fail.",
|
|
9
|
+
once=True,
|
|
10
|
+
) }}
|
|
11
|
+
{% endblock logs %}
|