mkdocstrings-python-xref 1.6.2__tar.gz → 1.14.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: mkdocstrings-python-xref
3
- Version: 1.6.2
3
+ Version: 1.14.0
4
4
  Summary: Enhanced mkdocstrings python handler
5
5
  Project-URL: Repository, https://github.com/analog-garage/mkdocstrings-python-xref
6
6
  Project-URL: Documentation, https://analog-garage.github.io/mkdocstrings-python-xref/
@@ -9,15 +9,15 @@ License-File: LICENSE.md
9
9
  Keywords: documentation-tool,mkdocstrings,mkdocstrings-handler,python
10
10
  Classifier: Development Status :: 3 - Alpha
11
11
  Classifier: Intended Audience :: Developers
12
- Classifier: Programming Language :: Python :: 3.8
13
12
  Classifier: Programming Language :: Python :: 3.9
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Topic :: Software Development :: Documentation
18
- Requires-Python: >=3.8
18
+ Requires-Python: >=3.9
19
19
  Requires-Dist: griffe>=1.0
20
- Requires-Dist: mkdocstrings-python<2.0,>=1.6.2
20
+ Requires-Dist: mkdocstrings-python<2.0,>=1.14
21
21
  Description-Content-Type: text/markdown
22
22
 
23
23
  # mkdocstrings-python-xref
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2022-2023. Analog Devices Inc.
1
+ # Copyright (c) 2022-2025. Analog Devices Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -15,8 +15,7 @@
15
15
  Extended mkdocstrings python handler
16
16
  """
17
17
 
18
- from .handler import PythonRelXRefHandler
18
+ from .handler import get_handler
19
19
 
20
20
  __all__ = ["get_handler"]
21
21
 
22
- get_handler = PythonRelXRefHandler
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2022-2024. Analog Devices Inc.
1
+ # Copyright (c) 2022-2025. Analog Devices Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -322,7 +322,7 @@ def substitute_relative_crossrefs(obj: Object, checkref: Optional[Callable[[str]
322
322
  """Recursively expand relative cross-references in all docstrings in tree.
323
323
 
324
324
  Arguments:
325
- obj: a Griffe [Object][griffe.] whose docstrings should be modified
325
+ obj: a Griffe [Object][griffe.dataclasses.] whose docstrings should be modified
326
326
  checkref: optional function to check whether computed cross-reference is valid.
327
327
  Should return True if valid, False if not valid.
328
328
  """
@@ -0,0 +1,159 @@
1
+ # Copyright (c) 2022-2025. Analog Devices Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """
15
+ Implementation of python_xref handler
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import sys
21
+ from dataclasses import dataclass, fields
22
+ from pathlib import Path
23
+ from textwrap import dedent
24
+ from typing import Annotated, Any, ClassVar, Mapping, MutableMapping, Optional
25
+ from warnings import warn
26
+
27
+ from mkdocs.config.defaults import MkDocsConfig
28
+ from mkdocstrings.handlers.base import CollectorItem
29
+ from mkdocstrings.loggers import get_logger
30
+ from mkdocstrings_handlers.python.config import PythonOptions, Field, PythonConfig
31
+ from mkdocstrings_handlers.python.handler import PythonHandler
32
+
33
+ from .crossref import substitute_relative_crossrefs
34
+
35
+ __all__ = [
36
+ 'PythonRelXRefHandler'
37
+ ]
38
+
39
+ logger = get_logger(__name__)
40
+
41
+
42
+ # TODO mkdocstrings 0.28
43
+ # - `name` and `domain` (py) must be specified as class attributes
44
+ # - `handler` arg to superclass is deprecated
45
+ # - add `mdx` arg to constructor to pass on to superclass
46
+ # - `config_file_path` arg will no longer be passed
47
+ #
48
+
49
+ # TODO python 3.9 - remove when 3.9 support is dropped
50
+ _dataclass_options = {"frozen": True}
51
+ if sys.version_info >= (3, 10):
52
+ _dataclass_options["kw_only"] = True
53
+
54
+ @dataclass(**_dataclass_options)
55
+ class PythonRelXRefOptions(PythonOptions):
56
+ check_crossrefs: Annotated[
57
+ bool,
58
+ Field(
59
+ group="docstrings",
60
+ parent="docstring_options",
61
+ description=dedent(
62
+ """
63
+ Enables early checking of all cross-references.
64
+
65
+ Note that this option only takes affect if **relative_crossrefs** is
66
+ also true. This option is true by default, so this option is used to
67
+ disable checking. Checking can also be disabled on a per-case basis by
68
+ prefixing the reference with '?', e.g. `[something][?dontcheckme]`.
69
+ """
70
+ ),
71
+ ),
72
+ ] = True
73
+
74
+ class PythonRelXRefHandler(PythonHandler):
75
+ """Extended version of mkdocstrings Python handler
76
+
77
+ * Converts relative cross-references into full references
78
+ * Checks cross-references early in order to produce errors with source location
79
+ """
80
+
81
+ name: ClassVar[str] = "python_xref"
82
+ """Override the handler name"""
83
+
84
+ def __init__(self, config: PythonConfig, base_dir: Path, **kwargs: Any) -> None:
85
+ """Initialize the handler.
86
+
87
+ Parameters:
88
+ config: The handler configuration.
89
+ base_dir: The base directory of the project.
90
+ **kwargs: Arguments passed to the parent constructor.
91
+ """
92
+ check_crossrefs = config.options.pop('check_crossrefs', None) # Remove
93
+ super().__init__(config, base_dir, **kwargs)
94
+ if check_crossrefs is not None:
95
+ self.global_options["check_crossrefs"] = check_crossrefs
96
+
97
+ def get_options(self, local_options: Mapping[str, Any]) -> PythonRelXRefOptions:
98
+ local_options = dict(local_options)
99
+ check_crossrefs = local_options.pop('check_crossrefs', None)
100
+ _opts = super().get_options(local_options)
101
+ opts = PythonRelXRefOptions(
102
+ **{field.name: getattr(_opts, field.name) for field in fields(_opts)}
103
+ )
104
+ if check_crossrefs is not None:
105
+ opts.check_crossrefs = bool(check_crossrefs)
106
+ return opts
107
+
108
+ def render(self, data: CollectorItem, options: PythonOptions) -> str:
109
+ if options.relative_crossrefs:
110
+ if isinstance(options, PythonRelXRefOptions):
111
+ checkref = self._check_ref if options.check_crossrefs else None
112
+ else:
113
+ checkref = None
114
+ substitute_relative_crossrefs(data, checkref=checkref)
115
+
116
+ try:
117
+ return super().render(data, options)
118
+ except Exception: # pragma: no cover
119
+ print(f"{data.path=}")
120
+ raise
121
+
122
+ def get_templates_dir(self, handler: Optional[str] = None) -> Path:
123
+ """See [render][.barf]"""
124
+ if handler == self.name:
125
+ handler = 'python'
126
+ return super().get_templates_dir(handler)
127
+
128
+ def _check_ref(self, ref:str) -> bool:
129
+ """Check for existence of reference"""
130
+ try:
131
+ self.collect(ref, PythonOptions())
132
+ return True
133
+ except Exception: # pylint: disable=broad-except
134
+ # Only expect a CollectionError but we may as well catch everything.
135
+ return False
136
+
137
+ def get_handler(
138
+ handler_config: MutableMapping[str, Any],
139
+ tool_config: MkDocsConfig,
140
+ **kwargs: Any,
141
+ ) -> PythonHandler:
142
+ """Simply return an instance of `PythonRelXRefHandler`.
143
+
144
+ Arguments:
145
+ handler_config: The handler configuration.
146
+ tool_config: The tool (SSG) configuration.
147
+
148
+ Returns:
149
+ An instance of `PythonRelXRefHandler`.
150
+ """
151
+ base_dir = Path(tool_config.config_file_path or "./mkdocs.yml").parent
152
+ if "inventories" not in handler_config and "import" in handler_config:
153
+ warn("The 'import' key is renamed 'inventories' for the Python handler", FutureWarning, stacklevel=1)
154
+ handler_config["inventories"] = handler_config.pop("import", [])
155
+ return PythonRelXRefHandler(
156
+ config=PythonConfig.from_data(**handler_config),
157
+ base_dir=base_dir,
158
+ **kwargs,
159
+ )
@@ -13,19 +13,19 @@ classifiers = [
13
13
  "Development Status :: 3 - Alpha",
14
14
  "Intended Audience :: Developers",
15
15
  "Topic :: Software Development :: Documentation",
16
- "Programming Language :: Python :: 3.8",
17
16
  "Programming Language :: Python :: 3.9",
18
17
  "Programming Language :: Python :: 3.10",
19
18
  "Programming Language :: Python :: 3.11",
20
19
  "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
21
  ]
22
22
  keywords = [
23
23
  "documentation-tool", "mkdocstrings", "mkdocstrings-handler", "python"
24
24
  ]
25
25
  dynamic = ["version"]
26
- requires-python = ">=3.8"
26
+ requires-python = ">=3.9"
27
27
  dependencies = [
28
- "mkdocstrings-python >=1.6.2,<2.0",
28
+ "mkdocstrings-python >=1.14,<2.0",
29
29
  "griffe >=1.0"
30
30
  ]
31
31
 
@@ -47,13 +47,13 @@ include = [
47
47
  [tool.hatch.build.targets.sdist]
48
48
  packages = [
49
49
  "src/mkdocstrings_handlers",
50
- "src/mkdocstrings_handlers/python_xref",
50
+ # "src/mkdocstrings_handlers/python_xref",
51
51
  ]
52
52
 
53
53
  [tool.hatch.build.targets.wheel]
54
54
  packages = [
55
55
  "src/mkdocstrings_handlers",
56
- "src/mkdocstrings_handlers/python_xref",
56
+ # "src/mkdocstrings_handlers/python_xref",
57
57
  ]
58
58
 
59
59
  [tool.mypy]
@@ -1,95 +0,0 @@
1
- # Copyright (c) 2022=2023. Analog Devices Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """
15
- Implementation of python_xref handler
16
- """
17
-
18
- from __future__ import annotations
19
-
20
- from collections import ChainMap
21
- from pathlib import Path
22
- from typing import Any, List, Mapping, Optional
23
-
24
- from griffe import Object
25
- from mkdocstrings.loggers import get_logger
26
- from mkdocstrings_handlers.python.handler import PythonHandler
27
-
28
- from .crossref import substitute_relative_crossrefs
29
-
30
- __all__ = [
31
- 'PythonRelXRefHandler'
32
- ]
33
-
34
- logger = get_logger(__name__)
35
-
36
- class PythonRelXRefHandler(PythonHandler):
37
- """Extended version of mkdocstrings Python handler
38
-
39
- * Converts relative cross-references into full references
40
- * Checks cross-references early in order to produce errors with source location
41
- """
42
-
43
- handler_name: str = __name__.rsplit('.', 2)[1]
44
-
45
- default_config = dict(
46
- PythonHandler.default_config,
47
- relative_crossrefs = False,
48
- check_crossrefs = True,
49
- )
50
-
51
- def __init__(self,
52
- theme: str,
53
- custom_templates: Optional[str] = None,
54
- config_file_path: Optional[str] = None,
55
- paths: Optional[List[str]] = None,
56
- locale: str = "en",
57
- **_config: Any,
58
- ):
59
- super().__init__(
60
- handler = self.handler_name,
61
- theme = theme,
62
- custom_templates = custom_templates,
63
- config_file_path = config_file_path,
64
- paths = paths,
65
- locale=locale,
66
- )
67
-
68
- def render(self, data: Object, config: Mapping[str,Any]) -> str:
69
- final_config = ChainMap(config, self.default_config) # type: ignore[arg-type]
70
-
71
- if final_config["relative_crossrefs"]:
72
- checkref = self._check_ref if final_config["check_crossrefs"] else None
73
- substitute_relative_crossrefs(data, checkref=checkref)
74
-
75
- try:
76
- return super().render(data, config)
77
- except Exception: # pragma: no cover
78
- print(f"{data.path=}")
79
- raise
80
-
81
- def get_templates_dir(self, handler: Optional[str] = None) -> Path:
82
- """See [render][.barf]"""
83
- if handler == self.handler_name:
84
- handler = 'python'
85
- return super().get_templates_dir(handler)
86
-
87
- def _check_ref(self, ref:str) -> bool:
88
- """Check for existence of reference"""
89
- try:
90
- self.collect(ref, {})
91
- return True
92
- except Exception: # pylint: disable=broad-except
93
- # Only expect a CollectionError but we may as well catch everything.
94
- return False
95
-