|
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 ( |
|
30 | 28 | DocstringSectionModules, |
31 | 29 | Object, |
32 | 30 | ) |
33 | | -from jinja2 import TemplateNotFound, pass_context, pass_environment |
| 31 | +from jinja2 import pass_context |
34 | 32 | from markupsafe import Markup |
35 | 33 | from mkdocs_autorefs import AutorefsHookInterface, Backlink, BacklinkCrumb |
36 | 34 | from mkdocstrings import get_logger |
|
39 | 37 | from collections.abc import Iterable, Iterator, Sequence |
40 | 38 |
|
41 | 39 | from griffe import Attribute, Class, Function, Module |
42 | | - from jinja2 import Environment |
43 | 40 | from jinja2.runtime import Context |
44 | 41 | from mkdocstrings import CollectorItem |
45 | 42 |
|
@@ -160,8 +157,7 @@ def do_format_signature( |
160 | 157 | The same code, formatted. |
161 | 158 | """ |
162 | 159 | 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") |
165 | 161 |
|
166 | 162 | if annotations is None: |
167 | 163 | new_context = context.parent |
@@ -222,8 +218,7 @@ def do_format_attribute( |
222 | 218 | The same code, formatted. |
223 | 219 | """ |
224 | 220 | env = context.environment |
225 | | - # YORE: Bump 2: Replace `do_get_template(env, "expression")` with `"expression.html.jinja"` within line. |
226 | | - template = env.get_template(do_get_template(env, "expression")) |
| 221 | + template = env.get_template("expression.html.jinja") |
227 | 222 | annotations = context.parent["config"].show_signature_annotations |
228 | 223 |
|
229 | 224 | signature = str(attribute_path).strip() |
@@ -288,76 +283,6 @@ def do_order_members( |
288 | 283 | return members |
289 | 284 |
|
290 | 285 |
|
291 | | -# YORE: Bump 2: Remove block. |
292 | | -@lru_cache |
293 | | -def _warn_crossref() -> None: |
294 | | - warnings.warn( |
295 | | - "The `crossref` filter is deprecated and will be removed in a future version", |
296 | | - DeprecationWarning, |
297 | | - stacklevel=1, |
298 | | - ) |
299 | | - |
300 | | - |
301 | | -# YORE: Bump 2: Remove block. |
302 | | -def do_crossref(path: str, *, brief: bool = True) -> Markup: |
303 | | - """Deprecated. Filter to create cross-references. |
304 | | -
|
305 | | - Parameters: |
306 | | - path: The path to link to. |
307 | | - brief: Show only the last part of the path, add full path as hover. |
308 | | -
|
309 | | - Returns: |
310 | | - Markup text. |
311 | | - """ |
312 | | - _warn_crossref() |
313 | | - full_path = path |
314 | | - if brief: |
315 | | - path = full_path.split(".")[-1] |
316 | | - return Markup("<autoref identifier={full_path} optional hover>{path}</autoref>").format( |
317 | | - full_path=full_path, |
318 | | - path=path, |
319 | | - ) |
320 | | - |
321 | | - |
322 | | -# YORE: Bump 2: Remove block. |
323 | | -@lru_cache |
324 | | -def _warn_multi_crossref() -> None: |
325 | | - warnings.warn( |
326 | | - "The `multi_crossref` filter is deprecated and will be removed in a future version", |
327 | | - DeprecationWarning, |
328 | | - stacklevel=1, |
329 | | - ) |
330 | | - |
331 | | - |
332 | | -# YORE: Bump 2: Remove block. |
333 | | -def do_multi_crossref(text: str, *, code: bool = True) -> Markup: |
334 | | - """Deprecated. Filter to create cross-references. |
335 | | -
|
336 | | - Parameters: |
337 | | - text: The text to scan. |
338 | | - code: Whether to wrap the result in a code tag. |
339 | | -
|
340 | | - Returns: |
341 | | - Markup text. |
342 | | - """ |
343 | | - _warn_multi_crossref() |
344 | | - group_number = 0 |
345 | | - variables = {} |
346 | | - |
347 | | - def repl(match: Match) -> str: |
348 | | - nonlocal group_number |
349 | | - group_number += 1 |
350 | | - path = match.group() |
351 | | - path_var = f"path{group_number}" |
352 | | - variables[path_var] = path |
353 | | - return f"<autoref identifier={{{path_var}}} optional hover>{{{path_var}}}</autoref>" |
354 | | - |
355 | | - text = re.sub(r"([\w.]+)", repl, text) |
356 | | - if code: |
357 | | - text = f"<code>{text}</code>" |
358 | | - return Markup(text).format(**variables) # noqa: S704 |
359 | | - |
360 | | - |
361 | 286 | _split_path_re = re.compile(r"([.(]?)([\w]+)(\))?") |
362 | 287 | _splitable_re = re.compile(r"[().]") |
363 | 288 |
|
@@ -572,39 +497,19 @@ def formatter(code: str, line_length: int) -> str: |
572 | 497 | return formatter |
573 | 498 |
|
574 | 499 |
|
575 | | -# YORE: Bump 2: Remove line. |
576 | | -@pass_environment |
577 | | -# YORE: Bump 2: Replace `env: Environment, ` with `` within line. |
578 | | -# YORE: Bump 2: Replace `str | ` with `` within line. |
579 | | -def do_get_template(env: Environment, obj: str | Object) -> str: |
| 500 | +def do_get_template(obj: Object) -> str: |
580 | 501 | """Get the template name used to render an object. |
581 | 502 |
|
582 | 503 | Parameters: |
583 | | - env: The Jinja environment, passed automatically. |
584 | 504 | obj: A Griffe object, or a template name. |
585 | 505 |
|
586 | 506 | Returns: |
587 | 507 | A template name. |
588 | 508 | """ |
589 | | - name = obj |
590 | | - if isinstance(obj, (Alias, Object)): |
591 | | - extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {}) |
592 | | - if name := extra_data.get("template", ""): |
593 | | - return name |
594 | | - name = obj.kind.value |
595 | | - # YORE: Bump 2: Replace block with `return f"{name}.html.jinja"`. |
596 | | - try: |
597 | | - template = env.get_template(f"{name}.html") |
598 | | - except TemplateNotFound: |
599 | | - return f"{name}.html.jinja" |
600 | | - our_template = Path(template.filename).is_relative_to(Path(__file__).parent.parent) # type: ignore[arg-type] |
601 | | - if our_template: |
602 | | - return f"{name}.html.jinja" |
603 | | - _logger.warning( |
604 | | - f"DeprecationWarning: Overriding '{name}.html' is deprecated, override '{name}.html.jinja' instead. ", |
605 | | - once=True, |
606 | | - ) |
607 | | - return f"{name}.html" |
| 509 | + extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {}) |
| 510 | + if template := extra_data.get("template", ""): |
| 511 | + return template |
| 512 | + return f"{obj.kind.value}.html.jinja" |
608 | 513 |
|
609 | 514 |
|
610 | 515 | @pass_context |
|
0 commit comments