Skip to content

Commit c10afdb

Browse files
committed
refactor: Remove deprecated code for v2
1 parent b5ef2f3 commit c10afdb

File tree

139 files changed

+168
-1047
lines changed

Some content is hidden

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

139 files changed

+168
-1047
lines changed

src/mkdocstrings_handlers/python/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
do_as_modules_section,
2525
do_as_type_aliases_section,
2626
do_backlink_tree,
27-
do_crossref,
2827
do_filter_objects,
2928
do_format_attribute,
3029
do_format_code,
3130
do_format_signature,
3231
do_format_type_alias,
3332
do_get_template,
34-
do_multi_crossref,
3533
do_order_members,
3634
do_split_path,
3735
do_stash_crossref,
@@ -59,14 +57,12 @@
5957
"do_as_modules_section",
6058
"do_as_type_aliases_section",
6159
"do_backlink_tree",
62-
"do_crossref",
6360
"do_filter_objects",
6461
"do_format_attribute",
6562
"do_format_code",
6663
"do_format_signature",
6764
"do_format_type_alias",
6865
"do_get_template",
69-
"do_multi_crossref",
7066
"do_order_members",
7167
"do_split_path",
7268
"do_stash_crossref",

src/mkdocstrings_handlers/python/_internal/handler.py

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from dataclasses import asdict
1111
from pathlib import Path
1212
from typing import TYPE_CHECKING, Any, BinaryIO, ClassVar
13-
from warnings import warn
1413

1514
from griffe import (
1615
AliasResolutionError,
@@ -56,17 +55,6 @@ def chdir(path: str) -> Iterator[None]:
5655
patch_loggers(get_logger)
5756

5857

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

@@ -97,18 +85,9 @@ def __init__(self, config: PythonConfig, base_dir: Path, **kwargs: Any) -> None:
9785
self.base_dir = base_dir
9886
"""The base directory of the project."""
9987

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

108-
# YORE: Bump 2: Replace `# ` with `` within block.
109-
# self.global_options = config.options
110-
# """The global configuration options (in `mkdocs.yml`)."""
111-
11291
# Warn if user overrides base templates.
11392
if self.custom_templates:
11493
for theme_dir in base_dir.joinpath(self.custom_templates, "python").iterdir():
@@ -188,25 +167,13 @@ def get_options(self, local_options: Mapping[str, Any]) -> HandlerOptions:
188167
Returns:
189168
The combined options.
190169
"""
191-
# YORE: Bump 2: Remove block.
192-
local_extra, local_options = PythonOptions._extract_extra(local_options) # type: ignore[arg-type]
193-
if local_extra:
194-
_warn_extra_options(local_extra.keys()) # type: ignore[arg-type]
195-
unknown_extra = self._global_extra | local_extra
196-
197170
extra = {**self.global_options.get("extra", {}), **local_options.get("extra", {})}
198171
options = {**self.global_options, **local_options, "extra": extra}
199172
try:
200-
# YORE: Bump 2: Replace `opts =` with `return` within line.
201-
opts = PythonOptions.from_data(**options)
173+
return PythonOptions.from_data(**options)
202174
except Exception as error:
203175
raise PluginError(f"Invalid options: {error}") from error
204176

205-
# YORE: Bump 2: Remove block.
206-
for key, value in unknown_extra.items():
207-
object.__setattr__(opts, key, value)
208-
return opts
209-
210177
def collect(self, identifier: str, options: PythonOptions) -> CollectorItem:
211178
"""Collect the documentation for the given identifier.
212179
@@ -291,7 +258,7 @@ def render(self, data: CollectorItem, options: PythonOptions, locale: str | None
291258
Returns:
292259
The rendered data (HTML).
293260
"""
294-
template_name = rendering.do_get_template(self.env, data)
261+
template_name = rendering.do_get_template(data)
295262
template = self.env.get_template(template_name)
296263

297264
return template.render(
@@ -303,8 +270,7 @@ def render(self, data: CollectorItem, options: PythonOptions, locale: str | None
303270
# than as an item in a dictionary.
304271
"heading_level": options.heading_level,
305272
"root": True,
306-
# YORE: Bump 2: Regex-replace ` or .+` with ` or "en",` within line.
307-
"locale": locale or self.config.locale,
273+
"locale": locale or "en",
308274
},
309275
)
310276

@@ -336,8 +302,6 @@ def update_env(self, config: Any) -> None: # noqa: ARG002
336302
self.env.lstrip_blocks = True
337303
self.env.keep_trailing_newline = False
338304
self.env.filters["split_path"] = rendering.do_split_path
339-
self.env.filters["crossref"] = rendering.do_crossref
340-
self.env.filters["multi_crossref"] = rendering.do_multi_crossref
341305
self.env.filters["order_members"] = rendering.do_order_members
342306
self.env.filters["format_code"] = rendering.do_format_code
343307
self.env.filters["format_signature"] = rendering.do_format_signature
@@ -435,9 +399,6 @@ def get_handler(
435399
sys.setrecursionlimit(max(sys.getrecursionlimit(), 2000))
436400

437401
base_dir = Path(getattr(tool_config, "config_file_path", None) or "./mkdocs.yml").parent
438-
if "inventories" not in handler_config and "import" in handler_config:
439-
warn("The 'import' key is renamed 'inventories' for the Python handler", FutureWarning, stacklevel=1)
440-
handler_config["inventories"] = handler_config.pop("import", [])
441402
return PythonHandler(
442403
config=PythonConfig.from_data(**handler_config),
443404
base_dir=base_dir,

src/mkdocstrings_handlers/python/_internal/rendering.py

Lines changed: 14 additions & 111 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 (
@@ -33,7 +31,7 @@
3331
Object,
3432
TypeAlias,
3533
)
36-
from jinja2 import TemplateNotFound, pass_context, pass_environment
34+
from jinja2 import pass_context
3735
from markupsafe import Markup
3836
from mkdocs_autorefs import AutorefsHookInterface, Backlink, BacklinkCrumb
3937
from mkdocstrings import get_logger
@@ -42,7 +40,6 @@
4240
from collections.abc import Iterable, Iterator, Sequence
4341

4442
from griffe import Attribute, Class, Function, Module
45-
from jinja2 import Environment
4643
from jinja2.runtime import Context
4744
from mkdocstrings import CollectorItem
4845

@@ -170,10 +167,8 @@ def do_format_signature(
170167
The same code, formatted.
171168
"""
172169
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")
177172

178173
if annotations is None:
179174
new_context = context.parent
@@ -237,8 +232,7 @@ def do_format_attribute(
237232
The same code, formatted.
238233
"""
239234
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")
242236
annotations = context.parent["config"].show_signature_annotations
243237

244238
signature = str(attribute_path).strip()
@@ -295,10 +289,8 @@ def do_format_type_alias(
295289
The same code, formatted.
296290
"""
297291
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")
302294

303295
signature = str(type_alias_path).strip()
304296
signature += type_params_template.render(context.parent, obj=type_alias, signature=True)
@@ -364,76 +356,6 @@ def do_order_members(
364356
return members
365357

366358

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-
437359
_split_path_re = re.compile(r"([.(]?)([\w]+)(\))?")
438360
_splitable_re = re.compile(r"[().]")
439361

@@ -648,39 +570,20 @@ def formatter(code: str, line_length: int) -> str:
648570
return formatter
649571

650572

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:
656574
"""Get the template name used to render an object.
657575
658576
Parameters:
659-
env: The Jinja environment, passed automatically.
660-
obj: A Griffe object, or a template name.
577+
obj: A Griffe object.
661578
662579
Returns:
663580
A template name.
664581
"""
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"
684587

685588

686589
@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.

0 commit comments

Comments
 (0)