5
5
from __future__ import annotations
6
6
7
7
import copy
8
- import posixpath
9
8
from collections import ChainMap
10
9
from pathlib import Path
11
10
from typing import (
12
11
Any ,
13
- BinaryIO ,
14
- Iterator ,
15
- Optional ,
16
- Tuple ,
17
12
MutableMapping ,
18
13
Dict ,
19
14
Mapping ,
20
15
Set ,
16
+ Tuple ,
21
17
)
22
18
23
- from griffe . logger import patch_loggers
19
+ from griffe import patch_loggers
24
20
from markdown import Markdown
25
21
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
28
23
from mkdocstrings .loggers import get_logger
29
24
30
25
from ._crossref import do_crossref , do_multi_crossref
@@ -49,14 +44,14 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
49
44
super ().__init__ (** kwargs )
50
45
self .base_dir = base_dir
51
46
52
- domain : str = "vba"
47
+ name : str = "vba"
53
48
"""
54
- The cross-documentation domain/language for this handler.
49
+ The handler's name .
55
50
"""
56
51
57
- enable_inventory : bool = True
52
+ domain : str = "vba"
58
53
"""
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 .
60
55
"""
61
56
62
57
fallback_theme = "material"
@@ -83,9 +78,7 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
83
78
"docstring_section_style" : "table" ,
84
79
}
85
80
"""
86
- The default rendering options.
87
-
88
- See [`default_config`][mkdocstrings_handlers.vba.renderer.VbaRenderer.default_config].
81
+ The default handler configuration.
89
82
90
83
Option | Type | Description | Default
91
84
------ | ---- | ----------- | -------
@@ -107,32 +100,38 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
107
100
**`docstring_section_style`** | `str` | The style used to render docstring sections. Options: `table`, `list`, `spacy`. | `table`
108
101
"""
109
102
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.
121
109
122
110
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.
127
113
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.
130
119
"""
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 ()
133
126
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
+ )
136
135
137
136
def render (
138
137
self ,
@@ -163,9 +162,6 @@ def render(
163
162
},
164
163
)
165
164
166
- def get_anchors (self , data : VbaModuleInfo ) -> Set [str ]:
167
- return {data .path .as_posix (), * (p .signature .name for p in data .procedures )}
168
-
169
165
def update_env (self , md : Markdown , config : Dict [Any , Any ]) -> None :
170
166
super ().update_env (md , config )
171
167
self .env .trim_blocks = True
@@ -175,38 +171,12 @@ def update_env(self, md: Markdown, config: Dict[Any, Any]) -> None:
175
171
self .env .filters ["multi_crossref" ] = do_multi_crossref
176
172
self .env .filters ["order_members" ] = do_order_members
177
173
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 )
207
176
208
177
209
178
def get_handler (
179
+ * ,
210
180
theme : str ,
211
181
custom_templates : str | None = None ,
212
182
config_file_path : str | None = None ,
@@ -229,11 +199,12 @@ def get_handler(
229
199
An instance of `VbaHandler`.
230
200
"""
231
201
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
+ ),
233
207
handler = "vba" ,
234
208
theme = theme ,
235
209
custom_templates = custom_templates ,
236
- config_file_path = config_file_path ,
237
- paths = paths ,
238
- locale = locale ,
239
210
)
0 commit comments