10000 refactor: Update for v2 (ran `yore fix -b2`) · mkdocstrings/python@d1cb293 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1cb293

Browse files
committed
refactor: Update for v2 (ran yore fix -b2)
1 parent e15fb74 commit d1cb293

File tree

126 files changed

+118
-928
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+118
-928
lines changed

src/mkdocstrings_handlers/python/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
do_as_functions_section,
2424
do_as_modules_section,
2525
do_backlink_tree,
26-
do_crossref,
2726
do_filter_objects,
2827
do_format_attribute,
2928
do_format_code,
3029
do_format_signature,
3130
do_get_template,
32-
do_multi_crossref,
3331
do_order_members,
3432
do_split_path,
3533
do_stash_crossref,
@@ -56,13 +54,11 @@
5654
"do_as_functions_section",
5755
"do_as_modules_section",
5856
"do_backlink_tree",
59-
"do_crossref",
6057
"do_filter_objects",
6158
"do_format_attribute",
6259
"do_format_code",
6360
"do_format_signature",
6461
"do_get_template",
65-
"do_multi_crossref",
6662
"do_order_members",
6763
"do_split_path",
6864
"do_stash_crossref",

src/mkdocstrings_handlers/python/_internal/handler.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ def chdir(path: str) -> Iterator[None]:
5454
patch_loggers(get_logger)
5555

5656

57-
# YORE: Bump 2: Remove block.
58-
def _warn_extra_options(names: Sequence[str]) -> None:
59-
warn(
60-
"Passing extra options directly under `options` is deprecated. "
61-
"Instead, pass them under `options.extra`, and update your templates. "
62-
f"Current extra (unrecognized) options: {', '.join(sorted(names))}",
63-
DeprecationWarning,
64-
stacklevel=3,
65-
)
66-
67-
6857
class PythonHandler(BaseHandler):
6958
"""The Python handler class."""
7059

@@ -95,18 +84,9 @@ def __init__(self, config: PythonConfig, base_dir: Path, **kwargs: Any) -> None:
9584
self.base_dir = base_dir
9685
"""The base directory of the project."""
9786

98-
# YORE: Bump 2: Remove block.
99-
global_extra, global_options = PythonOptions._extract_extra(config.options)
100-
if global_extra:
101-
_warn_extra_options(global_extra.keys()) # type: ignore[arg-type]
102-
self._global_extra = global_extra
103-
self.global_options = global_options
87+
self.global_options = config.options
10488
"""The global configuration options (in `mkdocs.yml`)."""
10589

106-
# YORE: Bump 2: Replace `# ` with `` within block.
107-
# self.global_options = config.options
108-
# """The global configuration options (in `mkdocs.yml`)."""
109-
11090
# Warn if user overrides base templates.
11191
if self.custom_templates:
11292
for theme_dir in base_dir.joinpath(self.custom_templates, "python").iterdir():
@@ -186,25 +166,13 @@ def get_options(self, local_options: Mapping[str, Any]) -> HandlerOptions:
186166
Returns:
187167
The combined options.
188168
"""
189-
# YORE: Bump 2: Remove block.
190-
local_extra, local_options = PythonOptions._extract_extra(local_options) # type: ignore[arg-type]
191-
if local_extra:
192-
_warn_extra_options(local_extra.keys()) # type: ignore[arg-type]
193-
unknown_extra = self._global_extra | local_extra
194-
195169
extra = {**self.global_options.get("extra", {}), **local_options.get("extra", {})}
196170
options = {**self.global_options, **local_options, "extra": extra}
197171
try:
198-
# YORE: Bump 2: Replace `opts =` with `return` within line.
199-
opts = PythonOptions.from_data(**options)
172+
return PythonOptions.from_data(**options)
200173
except Exception as error:
201174
raise PluginError(f"Invalid options: {error}") from error
202175

203-
# YORE: Bump 2: Remove block.
204-
for key, value in unknown_extra.items():
205-
object.__setattr__(opts, key, value)
206-
return opts
207-
208176
def collect(self, identifier: str, options: PythonOptions) -> CollectorItem:
209177
"""Collect the documentation for the given identifier.
210178
@@ -288,7 +256,7 @@ def render(self, data: CollectorItem, options: PythonOptions) -> str:
288256
Returns:
289257
The rendered data (HTML).
290258
"""
291-
template_name = rendering.do_get_template(self.env, data)
259+
template_name = rendering.do_get_template(data)
292260
template = self.env.get_template(template_name)
293261

294262
return template.render(
@@ -314,8 +282,6 @@ def update_env(self, config: Any) -> None: # noqa: ARG002
314282
self.env.lstrip_blocks = True
315283
self.env.keep_trailing_newline = False
316284
self.env.filters["split_path"] = rendering.do_split_path
317-
self.env.filters["crossref"] = rendering.do_crossref
318-
self.env.filters["multi_crossref"] = rendering.do_multi_crossref
319285
self.env.filters["order_members"] = rendering.do_order_members
320286
self.env.filters["format_code"] = rendering.do_format_code
321287
self.env.filters["format_signature"] = rendering.do_format_signature

src/mkdocstrings_handlers/python/_internal/rendering.py

Lines changed: 9 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import string
88
import subprocess
99
import sys
10-
import warnings
1110
from collections import defaultdict
1211
from contextlib import suppress
1312
from dataclasses import replace
1413
from functools import lru_cache
15-
from pathlib import Path
16-
from re import Match, Pattern
14+
from re import Pattern
1715
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Literal, TypeVar
1816

1917
from griffe import (
@@ -30,7 +28,7 @@
3028
DocstringSectionModules,
3129
Object,
3230
)
33-
from jinja2 import TemplateNotFound, pass_context, pass_environment
31+
from jinja2 import pass_context
3432
from markupsafe import Markup
3533
from mkdocs_autorefs import AutorefsHookInterface, Backlink, BacklinkCrumb
3634
from mkdocstrings import get_logger
@@ -39,7 +37,6 @@
3937
from collections.abc import Iterable, Iterator, Sequence
4038

4139
from griffe import Attribute, Class, Function, Module
42-
from jinja2 import Environment
4340
from jinja2.runtime import Context
4441
from mkdocstrings import CollectorItem
4542

@@ -160,8 +157,7 @@ def do_format_signature(
160157
The same code, formatted.
161158
"""
162159
env = context.environment
163-
# YORE: Bump 2: Replace `do_get_template(env, "signature")` with `"signature.html.jinja"` within line.
164-
template = env.get_template(do_get_template(env, "signature"))
160+
template = env.get_template("signature.html.jinja")
165161

166162
if annotations is None:
167163
new_context = context.parent
@@ -220,8 +216,7 @@ def do_format_attribute(
220216
The same code, formatted.
221217
"""
222218
env = context.environment
223-
# YORE: Bump 2: Replace `do_get_template(env, "expression")` with `"expression.html.jinja"` within line.
224-
template = env.get_template(do_get_template(env, "expression"))
219+
template = env.get_template("expression.html.jinja")
225220
annotations = context.parent["config"].show_signature_annotations
226221

227222
signature = str(attribute_path).strip()
@@ -286,76 +281,6 @@ def do_order_members(
286281
return members
287282

288283

289-
# YORE: Bump 2: Remove block.
290-
@lru_cache
291-
def _warn_crossref() -> None:
292-
warnings.warn(
293-
"The `crossref` filter is deprecated and will be removed in a future version",
294-
DeprecationWarning,
295-
stacklevel=1,
296-
)
297-
298-
299-
# YORE: Bump 2: Remove block.
300-
def do_crossref(path: str, *, brief: bool = True) -> Markup:
301-
"""Deprecated. Filter to create cross-references.
302-
303-
Parameters:
304-
path: The path to link to.
305-
brief: Show only the last part of the path, add full path as hover.
306-
307-
Returns:
308-
Markup text.
309-
"""
310-
_warn_crossref()
311-
full_path = path
312-
if brief:
313-
path = full_path.split(".")[-1]
314-
return Markup("<autoref identifier={full_path} optional hover>{path}</autoref>").format(
315-
full_path=full_path,
316-
path=path,
317-
)
318-
319-
320-
# YORE: Bump 2: Remove block.
321-
@lru_cache
322-
def _warn_multi_crossref() -> None:
323-
warnings.warn(
324-
"The `multi_crossref` filter is deprecated and will be removed in a future version",
325-
DeprecationWarning,
326-
stacklevel=1,
327-
)
328-
329-
330-
# YORE: Bump 2: Remove block.
331-
def do_multi_crossref(text: str, *, code: bool = True) -> Markup:
332-
"""Deprecated. Filter to create cross-references.
333-
334-
Parameters:
335-
text: The text to scan.
336-
code: Whether to wrap the result in a code tag.
337-
338-
Returns:
339-
Markup text.
340-
"""
341-
_warn_multi_crossref()
342-
group_number = 0
343 F438 -
variables = {}
344-
345-
def repl(match: Match) -> str:
346-
nonlocal group_number
347-
group_number += 1
348-
path = match.group()
349-
path_var = f"path{group_number}"
350-
variables[path_var] = path
351-
return f"<autoref identifier={{{path_var}}} optional hover>{{{path_var}}}</autoref>"
352-
353-
text = re.sub(r"([\w.]+)", repl, text)
354-
if code:
355-
text = f"<code>{text}</code>"
356-
return Markup(text).format(**variables) # noqa: S704
357-
358-
359284
_split_path_re = re.compile(r"([.(]?)([\w]+)(\))?")
360285
_splitable_re = re.compile(r"[().]")
361286

@@ -570,39 +495,19 @@ def formatter(code: str, line_length: int) -> str:
570495
return formatter
571496

572497

573-
# YORE: Bump 2: Remove line.
574-
@pass_environment
575-
# YORE: Bump 2: Replace `env: Environment, ` with `` within line.
576-
# YORE: Bump 2: Replace `str | ` with `` within line.
577-
def do_get_template(env: Environment, obj: str | Object) -> str:
498+
def do_get_template(obj: Object) -> str:
578499
"""Get the template name used to render an object.
579500
580501
Parameters:
581-
env: The Jinja environment, passed automatically.
582502
obj: A Griffe object, or a template name.
583503
584504
Returns:
585505
A template name.
586506
"""
587-
name = obj
588-
if isinstance(obj, (Alias, Object)):
589-
extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {})
590-
if name := extra_data.get("template", ""):
591-
return name
592-
name = obj.kind.value
593-
# YORE: Bump 2: Replace block with `return f"{name}.html.jinja"`.
594-
try:
595-
template = env.get_template(f"{name}.html")
596-
except TemplateNotFound:
597-
return f"{name}.html.jinja"
598-
our_template = Path(template.filename).is_relative_to(Path(__file__).parent.parent) # type: ignore[arg-type]
599-
if our_template:
600-
return f"{name}.html.jinja"
601-
_logger.warning(
602-
f"DeprecationWarning: Overriding '{name}.html' is deprecated, override '{name}.html.jinja' instead. ",
603-
once=True,
604-
)
605-
return f"{name}.html"
507+
extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {})
508+
if template := extra_data.get("template", ""):
509+
return template
510+
return f"{obj.kind.value}.html.jinja"
606511

607512

608513
@pass_context

src/mkdocstrings_handlers/python/config.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/mkdocstrings_handlers/python/handler.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/mkdocstrings_handlers/python/rendering.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/mkdocstrings_handlers/python/templates/material/_base/attribute.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/mkdocstrings_handlers/python/templates/material/_base/attribute.html.jinja

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ Context:
6464
This block renders the labels for the attribute.
6565
-#}
6666
{% with labels = attribute.labels %}
67-
{# YORE: Bump 2: Replace `"|get_template` with `.html.jinja"` within line. #}
68-
{% include "labels"|get_template with context %}
67+
{% include "labels.html.jinja" with context %}
6968
{% endwith %}
7069
{% endblock labels %}
7170

@@ -111,8 +110,7 @@ Context:
111110
This block renders the docstring for the attribute.
112111
-#}
113112
{% with docstring_sections = attribute.docstring.parsed %}
114-
{# YORE: Bump 2: Replace `"|get_template` with `.html.jinja"` within line. #}
115-
{% include "docstring"|get_template with context %}
113+
{% include "docstring.html.jinja" with context %}
116114
{% endwith %}
117115
{% endblock docstring %}
118116

src/mkdocstrings_handlers/python/templates/material/_base/children.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/mkdocstrings_handlers/python/templates/material/_base/class.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0