Skip to content

Commit 14d0fca

Browse files
authored
Merge pull request #20 from mkdocstrings/dev-upgrade
Update mkdocstrings and griffe to the latest versions.
2 parents 117a861 + b063c0b commit 14d0fca

File tree

7 files changed

+53
-83
lines changed

7 files changed

+53
-83
lines changed

Diff for: ci-constraints.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mkdocstrings==0.22.0
2-
griffe==0.34.0
1+
mkdocstrings==0.26.1
2+
griffe==1.3.1
33
mkdocs-material==9.2.1

Diff for: mkdocstrings_handlers/vba/_handler.py

+43-72
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@
55
from __future__ import annotations
66

77
import copy
8-
import posixpath
98
from collections import ChainMap
109
from pathlib import Path
1110
from typing import (
1211
Any,
13-
BinaryIO,
14-
Iterator,
15-
Optional,
16-
Tuple,
1712
MutableMapping,
1813
Dict,
1914
Mapping,
2015
Set,
16+
Tuple,
2117
)
2218

23-
from griffe.logger import patch_loggers
19+
from griffe import patch_loggers
2420
from markdown import Markdown
2521
from mkdocs.exceptions import PluginError
26-
from mkdocstrings.handlers.base import BaseHandler
27-
from mkdocstrings.inventory import Inventory
22+
from mkdocstrings.handlers.base import BaseHandler, CollectionError
2823
from mkdocstrings.loggers import get_logger
2924

3025
from ._crossref import do_crossref, do_multi_crossref
@@ -49,14 +44,14 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
4944
super().__init__(**kwargs)
5045
self.base_dir = base_dir
5146

52-
domain: str = "vba"
47+
name: str = "vba"
5348
"""
54-
The cross-documentation domain/language for this handler.
49+
The handler's name.
5550
"""
5651

57-
enable_inventory: bool = True
52+
domain: str = "vba"
5853
"""
59-
Whether this handler is interested in enabling the creation of the `objects.inv` Sphinx inventory file.
54+
The cross-documentation domain/language for this handler.
6055
"""
6156

6257
fallback_theme = "material"
@@ -83,9 +78,7 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
8378
"docstring_section_style": "table",
8479
}
8580
"""
86-
The default rendering options.
87-
88-
See [`default_config`][mkdocstrings_handlers.vba.renderer.VbaRenderer.default_config].
81+
The default handler configuration.
8982
9083
Option | Type | Description | Default
9184
------ | ---- | ----------- | -------
@@ -107,32 +100,38 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
107100
**`docstring_section_style`** | `str` | The style used to render docstring sections. Options: `table`, `list`, `spacy`. | `table`
108101
"""
109102

110-
@classmethod
111-
def load_inventory(
112-
cls,
113-
in_file: BinaryIO,
114-
url: str,
115-
base_url: Optional[str] = None,
116-
**kwargs: Any,
117-
) -> Iterator[Tuple[str, str]]:
118-
"""Yield items and their URLs from an inventory file streamed from `in_file`.
119-
120-
This implements mkdocstrings' `load_inventory` "protocol" (see plugin.py).
103+
def collect(
104+
self,
105+
identifier: str,
106+
config: MutableMapping[str, Any],
107+
) -> VbaModuleInfo:
108+
"""Collect the documentation tree given an identifier and selection options.
121109
122110
Arguments:
123-
in_file: The binary file-like object to read the inventory from.
124-
url: The URL that this file is being streamed from (used to guess `base_url`).
125-
base_url: The URL that this inventory's sub-paths are relative to.
126-
**kwargs: Ignore additional arguments passed from the config.
111+
identifier: Which VBA file (.bas or .cls) to collect from.
112+
config: Selection options, used to alter the data collection.
127113
128-
Yields:
129-
Tuples of (item identifier, item URL).
114+
Raises:
115+
CollectionError: When there was a problem collecting the documentation.
116+
117+
Returns:
118+
The collected object tree.
130119
"""
131-
if base_url is None:
132-
base_url = posixpath.dirname(url)
120+
p = Path(self.base_dir, identifier)
121+
if not p.exists():
122+
raise CollectionError("File not found.")
123+
124+
with p.open("r") as f:
125+
code = f.read()
133126

134-
for item in Inventory.parse_sphinx(in_file, domain_filter=("py",)).values():
135-
yield item.name, posixpath.join(base_url, item.uri)
127+
code = collapse_long_lines(code)
128+
129+
return VbaModuleInfo(
130+
docstring=find_file_docstring(code),
131+
source=code.splitlines(),
132+
path=p,
133+
procedures=list(find_procedures(code)),
134+
)
136135

137136
def render(
138137
self,
@@ -163,9 +162,6 @@ def render(
163162
},
164163
)
165164

166-
def get_anchors(self, data: VbaModuleInfo) -> Set[str]:
167-
return {data.path.as_posix(), *(p.signature.name for p in data.procedures)}
168-
169165
def update_env(self, md: Markdown, config: Dict[Any, Any]) -> None:
170166
super().update_env(md, config)
171167
self.env.trim_blocks = True
@@ -175,38 +171,12 @@ def update_env(self, md: Markdown, config: Dict[Any, Any]) -> None:
175171
self.env.filters["multi_crossref"] = do_multi_crossref
176172
self.env.filters["order_members"] = do_order_members
177173

178-
def collect(
179-
self,
180-
identifier: str,
181-
config: MutableMapping[str, Any],
182-
) -> VbaModuleInfo:
183-
"""Collect the documentation tree given an identifier and selection options.
184-
185-
Arguments:
186-
identifier: Which VBA file (.bas or .cls) to collect from.
187-
config: Selection options, used to alter the data collection.
188-
189-
Raises:
190-
CollectionError: When there was a problem collecting the documentation.
191-
192-
Returns:
193-
The collected object tree.
194-
"""
195-
p = Path(self.base_dir, identifier)
196-
with p.open("r") as f:
197-
code = f.read()
198-
199-
code = collapse_long_lines(code)
200-
201-
return VbaModuleInfo(
202-
docstring=find_file_docstring(code),
203-
source=code.splitlines(),
204-
path=p,
205-
procedures=list(find_procedures(code)),
206-
)
174+
def get_anchors(self, data: VbaModuleInfo) -> Tuple[str, ...]:
175+
return data.path.as_posix(), *(p.signature.name for p in data.procedures)
207176

208177

209178
def get_handler(
179+
*,
210180
theme: str,
211181
custom_templates: str | None = None,
212182
config_file_path: str | None = None,
@@ -229,11 +199,12 @@ def get_handler(
229199
An instance of `VbaHandler`.
230200
"""
231201
return VbaHandler(
232-
base_dir=Path(config_file_path or ".").parent,
202+
base_dir=(
203+
Path(config_file_path).resolve().parent
204+
if config_file_path
205+
else Path(".").resolve()
206+
),
233207
handler="vba",
234208
theme=theme,
235209
custom_templates=custom_templates,
236-
config_file_path=config_file_path,
237-
paths=paths,
238-
locale=locale,
239210
)

Diff for: mkdocstrings_handlers/vba/_sort.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
from typing import Any, Sequence
66

7-
from griffe.dataclasses import Alias, Object
7+
from griffe import Alias, Object
88
from mkdocstrings.handlers.base import CollectorItem
99

1010

Diff for: mkdocstrings_handlers/vba/_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from typing import List, Optional
44

5-
from griffe.dataclasses import Docstring
5+
from griffe import Docstring
66

77

88
@dataclass

Diff for: mkdocstrings_handlers/vba/_util.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import re
22
from typing import List, Generator
33

4-
from griffe.dataclasses import Docstring, Function, Parameters, Parameter
5-
from griffe.docstrings import Parser
4+
from griffe import Docstring, Function, Parameters, Parameter, Parser
65

76
from ._regex import re_signature, re_arg
87
from ._types import (

Diff for: mypy-requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mypy==1.5.1
2-
types-setuptools
3-
types-Markdown
1+
mypy==1.11.2
2+
types-setuptools==75.*
3+
types-Markdown==3.*

Diff for: setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"setuptools_scm",
2929
],
3030
install_requires=[
31-
"mkdocstrings>=0.22,<0.23",
32-
"griffe>=0.34,<0.35",
31+
"mkdocstrings>=0.26.1,<1",
32+
"griffe>=1.3.1,<2",
3333
"mkdocs-material>=9.2,<10",
3434
],
3535
include_package_data=True,

0 commit comments

Comments
 (0)