Skip to content

Commit 347ce76

Browse files
committed
refactor: Merge default configuration options in handler
1 parent b6c9893 commit 347ce76

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

docs/usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Option | Description
4141

4242
### Rendering
4343

44-
::: mkdocstrings_handlers.python.handler.PythonHandler.default_rendering_config
44+
::: mkdocstrings_handlers.python.handler.PythonHandler.default_config
4545
rendering:
4646
show_root_toc_entry: false
4747

src/mkdocstrings_handlers/python/handler.py

+29-27
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,17 @@ class PythonHandler(BaseHandler):
3838
of the `objects.inv` Sphinx inventory file.
3939
fallback_theme: The fallback theme.
4040
fallback_config: The configuration used to collect item during autorefs fallback.
41-
default_collection_config: The default rendering options,
42-
see [`default_collection_config`][mkdocstrings_handlers.python.handler.PythonHandler.default_collection_config].
43-
default_rendering_config: The default rendering options,
44-
see [`default_rendering_config`][mkdocstrings_handlers.python.handler.PythonHandler.default_rendering_config].
41+
default_config: The default rendering options,
42+
see [`default_config`][mkdocstrings_handlers.python.handler.PythonHandler.default_config].
4543
"""
4644

4745
domain: str = "py" # to match Sphinx's default domain
4846
enable_inventory: bool = True
4947
fallback_theme = "material"
5048
fallback_config: dict = {"fallback": True}
51-
default_collection_config: dict = {"docstring_style": "google", "docstring_options": {}}
52-
"""The default collection options.
53-
54-
Option | Type | Description | Default
55-
------ | ---- | ----------- | -------
56-
**`docstring_style`** | `"google" | "numpy" | "sphinx" | None` | The docstring style to use. | `"google"`
57-
**`docstring_options`** | `dict[str, Any]` | The options for the docstring parser. | `{}`
58-
"""
59-
default_rendering_config: dict = {
49+
default_config: dict = {
50+
"docstring_style": "google",
51+
"docstring_options": {},
6052
"show_root_heading": False,
6153
"show_root_toc_entry": True,
6254
"show_root_full_path": True,
@@ -81,30 +73,40 @@ class PythonHandler(BaseHandler):
8173
"annotations_path": "brief",
8274
}
8375
"""
84-
Attributes: Default rendering options:
76+
Attributes: Headings options:
77+
heading_level (int): The initial heading level to use. Default: `2`.
8578
show_root_heading (bool): Show the heading of the object at the root of the documentation tree. Default: `False`.
8679
show_root_toc_entry (bool): If the root heading is not shown, at least add a ToC entry for it. Default: `True`.
8780
show_root_full_path (bool): Show the full Python path for the root object heading. Default: `True`.
8881
show_root_members_full_path (bool): Show the full Python path of every object. Default: `False`.
8982
show_object_full_path (bool): Show the full Python path of objects that are children of the root object (for example, classes in a module). When False, `show_object_full_path` overrides. Default: `False`.
9083
show_category_heading (bool): When grouped by categories, show a heading for each category. Default: `False`.
84+
85+
Attributes: Members options:
86+
members (list[str] | False | None): An explicit list of members to render. Default: `None`.
87+
filters (list[str] | None): A list of filters applied to filter objects based on their name.
88+
A filter starting with `!` will exclude matching objects instead of including them. Default: `["!^_[^_]"]`.
89+
group_by_category (bool): Group the object's children by categories: attributes, classes, functions, methods, and modules. Default: `True`.
90+
show_submodules (bool): When rendering a module, show its submodules recursively. Default: `True`.
91+
members_order (str): The members ordering to use. Options: `alphabetical` - order by the members names, `source` - order members as they appear in the source file. Default: `"alphabetical"`.
92+
93+
Attributes: Docstrings options:
94+
docstring_style (str): The docstring style to use: `google`, `numpy`, `sphinx`, or `None`. Default: `"google"`.
95+
docstring_options (dict): The options for the docstring parser. See parsers under [`griffe.docstrings`][].
96+
docstring_section_style (str): The style used to render docstring sections. Options: `table`, `list`, `spacy`. Default: `"table"`.
97+
line_length (int): Maximum line length when formatting code. Default: `60`.
98+
merge_init_into_class (bool): Whether to merge the `__init__` method into the class' signature and docstring. Default: `False`.
9199
show_if_no_docstring (bool): Show the object heading even if it has no docstring or children with docstrings. Default: `False`.
100+
101+
Attributes: Signature/annotations options:
92102
annotations_path: The verbosity for annotations path: `brief` (recommended), or `source` (as written in the source). Default: `"brief"`.
93103
show_signature (bool): Show method and function signatures. Default: `True`.
94104
show_signature_annotations (bool): Show the type annotations in method and function signatures. Default: `False`.
95105
separate_signature (bool): Whether to put the whole signature in a code block below the heading. Default: `False`.
96-
line_length (int): Maximum line length when formatting code. Default: `60`.
97-
merge_init_into_class (bool): Whether to merge the `__init__` method into the class' signature and docstring. Default: `False`.
98-
show_source (bool): Show the source code of this object. Default: `True`.
106+
107+
Attributes: Additional options:
99108
show_bases (bool): Show the base classes of a class. Default: `True`.
100-
show_submodules (bool): When rendering a module, show its submodules recursively. Default: `True`.
101-
group_by_category (bool): Group the object's children by categories: attributes, classes, functions, methods, and modules. Default: `True`.
102-
heading_level (int): The initial heading level to use. Default: `2`.
103-
members_order (str): The members ordering to use. Options: `alphabetical` - order by the members names, `source` - order members as they appear in the source file. Default: `alphabetical`.
104-
docstring_section_style (str): The style used to render docstring sections. Options: `table`, `list`, `spacy`. Default: `table`.
105-
members (list[str] | False | None): An explicit list of members to render. Default: `None`.
106-
filters (list[str] | None): A list of filters applied to filter objects based on their name.
107-
A filter starting with `!` will exclude matching objects instead of including them. Default: `["!^_[^_]"]`.
109+
show_source (bool): Show the source code of this object. Default: `True`.
108110
""" # noqa: E501
109111

110112
def __init__(
@@ -167,7 +169,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102
167169
if config.get("fallback", False) and unknown_module:
168170
raise CollectionError("Not loading additional modules during fallback")
169171

170-
final_config = ChainMap(config, self.default_collection_config)
172+
final_config = ChainMap(config, self.default_config)
171173
parser_name = final_config["docstring_style"]
172174
parser_options = final_config["docstring_options"]
173175
parser = parser_name and Parser(parser_name)
@@ -204,7 +206,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102
204206
return doc_object
205207

206208
def render(self, data: CollectorItem, config: dict) -> str: # noqa: D102 (ignore missing docstring)
207-
final_config = ChainMap(config, self.default_rendering_config)
209+
final_config = ChainMap(config, self.default_config)
208210

209211
template = self.env.get_template(f"{data.kind.value}.html")
210212

0 commit comments

Comments
 (0)