|
7 | 7 | import string |
8 | 8 | import subprocess |
9 | 9 | import sys |
10 | | -import warnings |
11 | 10 | from collections import defaultdict |
12 | 11 | from contextlib import suppress |
13 | 12 | from dataclasses import replace |
14 | 13 | from functools import lru_cache |
15 | | -from pathlib import Path |
16 | | -from re import Match, Pattern |
| 14 | +from re import Pattern |
17 | 15 | from typing import TYPE_CHECKING, Any, Callable, ClassVar, Literal, TypeVar |
18 | 16 |
|
19 | 17 | from griffe import ( |
|
33 | 31 | Object, |
34 | 32 | TypeAlias, |
35 | 33 | ) |
36 | | -from jinja2 import TemplateNotFound, pass_context, pass_environment |
| 34 | +from jinja2 import pass_context |
37 | 35 | from markupsafe import Markup |
38 | 36 | from mkdocs_autorefs import AutorefsHookInterface, Backlink, BacklinkCrumb |
39 | 37 | from mkdocstrings import get_logger |
|
42 | 40 | from collections.abc import Iterable, Iterator, Sequence |
43 | 41 |
|
44 | 42 | from griffe import Attribute, Class, Function, Module |
45 | | - from jinja2 import Environment |
46 | 43 | from jinja2.runtime import Context |
47 | 44 | from mkdocstrings import CollectorItem |
48 | 45 |
|
@@ -170,10 +167,8 @@ def do_format_signature( |
170 | 167 | The same code, formatted. |
171 | 168 | """ |
172 | 169 | env = context.environment |
173 | | - # YORE: Bump 2: Replace `do_get_template(env, "type_parameters")` with `"type_parameters.html.jinja"` within line. |
174 | | - type_params_template = env.get_template(do_get_template(env, "type_parameters")) |
175 | | - # YORE: Bump 2: Replace `do_get_template(env, "signature")` with `"signature.html.jinja"` within line. |
176 | | - signature_template = env.get_template(do_get_template(env, "signature")) |
| 170 | + type_params_template = env.get_template("type_parameters.html.jinja") |
| 171 | + signature_template = env.get_template("signature.html.jinja") |
177 | 172 |
|
178 | 173 | if annotations is None: |
179 | 174 | new_context = context.parent |
@@ -237,8 +232,7 @@ def do_format_attribute( |
237 | 232 | The same code, formatted. |
238 | 233 | """ |
239 | 234 | env = context.environment |
240 | | - # YORE: Bump 2: Replace `do_get_template(env, "expression")` with `"expression.html.jinja"` within line. |
241 | | - template = env.get_template(do_get_template(env, "expression")) |
| 235 | + template = env.get_template("expression.html.jinja") |
242 | 236 | annotations = context.parent["config"].show_signature_annotations |
243 | 237 |
|
244 | 238 | signature = str(attribute_path).strip() |
@@ -295,10 +289,8 @@ def do_format_type_alias( |
295 | 289 | The same code, formatted. |
296 | 290 | """ |
297 | 291 | env = context.environment |
298 | | - # YORE: Bump 2: Replace `do_get_template(env, "type_parameters")` with `"type_parameters.html.jinja"` within line. |
299 | | - type_params_template = env.get_template(do_get_template(env, "type_parameters")) |
300 | | - # YORE: Bump 2: Replace `do_get_template(env, "expression")` with `"expression.html.jinja"` within line. |
301 | | - expr_template = env.get_template(do_get_template(env, "expression")) |
| 292 | + type_params_template = env.get_template("type_parameters.html.jinja") |
| 293 | + expr_template = env.get_template("expression.html.jinja") |
302 | 294 |
|
303 | 295 | signature = str(type_alias_path).strip() |
304 | 296 | signature += type_params_template.render(context.parent, obj=type_alias, signature=True) |
@@ -364,76 +356,6 @@ def do_order_members( |
364 | 356 | return members |
365 | 357 |
|
366 | 358 |
|
367 | | -# YORE: Bump 2: Remove block. |
368 | | -@lru_cache |
369 | | -def _warn_crossref() -> None: |
370 | | - warnings.warn( |
371 | | - "The `crossref` filter is deprecated and will be removed in a future version", |
372 | | - DeprecationWarning, |
373 | | - stacklevel=1, |
374 | | - ) |
375 | | - |
376 | | - |
377 | | -# YORE: Bump 2: Remove block. |
378 | | -def do_crossref(path: str, *, brief: bool = True) -> Markup: |
379 | | - """Deprecated. Filter to create cross-references. |
380 | | -
|
381 | | - Parameters: |
382 | | - path: The path to link to. |
383 | | - brief: Show only the last part of the path, add full path as hover. |
384 | | -
|
385 | | - Returns: |
386 | | - Markup text. |
387 | | - """ |
388 | | - _warn_crossref() |
389 | | - full_path = path |
390 | | - if brief: |
391 | | - path = full_path.split(".")[-1] |
392 | | - return Markup("<autoref identifier={full_path} optional hover>{path}</autoref>").format( |
393 | | - full_path=full_path, |
394 | | - path=path, |
395 | | - ) |
396 | | - |
397 | | - |
398 | | -# YORE: Bump 2: Remove block. |
399 | | -@lru_cache |
400 | | -def _warn_multi_crossref() -> None: |
401 | | - warnings.warn( |
402 | | - "The `multi_crossref` filter is deprecated and will be removed in a future version", |
403 | | - DeprecationWarning, |
404 | | - stacklevel=1, |
405 | | - ) |
406 | | - |
407 | | - |
408 | | -# YORE: Bump 2: Remove block. |
409 | | -def do_multi_crossref(text: str, *, code: bool = True) -> Markup: |
410 | | - """Deprecated. Filter to create cross-references. |
411 | | -
|
412 | | - Parameters: |
413 | | - text: The text to scan. |
414 | | - code: Whether to wrap the result in a code tag. |
415 | | -
|
416 | | - Returns: |
417 | | - Markup text. |
418 | | - """ |
419 | | - _warn_multi_crossref() |
420 | | - group_number = 0 |
421 | | - variables = {} |
422 | | - |
423 | | - def repl(match: Match) -> str: |
424 | | - nonlocal group_number |
425 | | - group_number += 1 |
426 | | - path = match.group() |
427 | | - path_var = f"path{group_number}" |
428 | | - variables[path_var] = path |
429 | | - return f"<autoref identifier={{{path_var}}} optional hover>{{{path_var}}}</autoref>" |
430 | | - |
431 | | - text = re.sub(r"([\w.]+)", repl, text) |
432 | | - if code: |
433 | | - text = f"<code>{text}</code>" |
434 | | - return Markup(text).format(**variables) # noqa: S704 |
435 | | - |
436 | | - |
437 | 359 | _split_path_re = re.compile(r"([.(]?)([\w]+)(\))?") |
438 | 360 | _splitable_re = re.compile(r"[().]") |
439 | 361 |
|
@@ -648,39 +570,20 @@ def formatter(code: str, line_length: int) -> str: |
648 | 570 | return formatter |
649 | 571 |
|
650 | 572 |
|
651 | | -# YORE: Bump 2: Remove line. |
652 | | -@pass_environment |
653 | | -# YORE: Bump 2: Replace `env: Environment, ` with `` within line. |
654 | | -# YORE: Bump 2: Replace `str | ` with `` within line. |
655 | | -def do_get_template(env: Environment, obj: str | Object) -> str: |
| 573 | +def do_get_template(obj: Object | Alias) -> str: |
656 | 574 | """Get the template name used to render an object. |
657 | 575 |
|
658 | 576 | Parameters: |
659 | | - env: The Jinja environment, passed automatically. |
660 | | - obj: A Griffe object, or a template name. |
| 577 | + obj: A Griffe object. |
661 | 578 |
|
662 | 579 | Returns: |
663 | 580 | A template name. |
664 | 581 | """ |
665 | | - name = obj |
666 | | - if isinstance(obj, (Alias, Object)): |
667 | | - extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {}) |
668 | | - if name := extra_data.get("template", ""): |
669 | | - return name |
670 | | - name = obj.kind.value.replace(" ", "_") |
671 | | - # YORE: Bump 2: Replace block with `return f"{name}.html.jinja"`. |
672 | | - try: |
673 | | - template = env.get_template(f"{name}.html") |
674 | | - except TemplateNotFound: |
675 | | - return f"{name}.html.jinja" |
676 | | - our_template = Path(template.filename).is_relative_to(Path(__file__).parent.parent) # type: ignore[arg-type] |
677 | | - if our_template: |
678 | | - return f"{name}.html.jinja" |
679 | | - _logger.warning( |
680 | | - f"DeprecationWarning: Overriding '{name}.html' is deprecated, override '{name}.html.jinja' instead. ", |
681 | | - once=True, |
682 | | - ) |
683 | | - return f"{name}.html" |
| 582 | + extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {}) |
| 583 | + if name := extra_data.get("template", ""): |
| 584 | + return name |
| 585 | + name = obj.kind.value.replace(" ", "_") |
| 586 | + return f"{name}.html.jinja" |
684 | 587 |
|
685 | 588 |
|
686 | 589 | @pass_context |
|
0 commit comments