55from __future__ import annotations
66
77import copy
8- import posixpath
98from collections import ChainMap
109from pathlib import Path
1110from 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
2420from markdown import Markdown
2521from 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
2823from mkdocstrings .loggers import get_logger
2924
3025from ._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
209178def 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 )
0 commit comments