Skip to content

Commit 3fe0c4e

Browse files
doc: document the configuration dict and how to configure the app
1 parent 2d186eb commit 3fe0c4e

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ Use the `-o`, `--output` option to write to a file instead of standard output:
3333
```bash
3434
griffe2md markdown -o markdown.md
3535
```
36+
37+
`griffe2md` can be configured by either 'pyproject.toml' or 'griffe2md.toml' files. The latter can be placed either in '.config' or 'config' directory in the project root.
38+
39+
'griffe2md.toml' file is structured as a simple key-value dictionary, e.g.:
40+
```toml
41+
docstring_style = "sphinx"
42+
```
43+
44+
If you configure it in `pyproject.toml`, the configuration should go under 'tool.griffe2md' key:
45+
```toml
46+
[tool.griffe2md]
47+
docstring_style = "sphinx"
48+
```
49+
50+
See [the documentation](https://mkdocstrings.github.io/griffe2md/reference/griffe2md/rendering/#griffe2md.rendering.ConfigDict) for reference.

src/griffe2md/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import logging
66
import sys
7+
import typing
78
from pathlib import Path
8-
from typing import Any
9+
10+
from griffe2md import rendering
911

1012
# YORE: EOL 3.10: Replace block with line 2.
1113
if sys.version_info >= (3, 11):
@@ -29,7 +31,7 @@ def _locate_config_file() -> Path | None:
2931
return None
3032

3133

32-
def load_config() -> dict[str, Any] | None:
34+
def load_config() -> rendering.ConfigDict | None:
3335
"""Load the configuration if config file or config entry in pyproject.toml exists.
3436
3537
If neither config file was found or pyproject.toml file doesn't have
@@ -45,4 +47,4 @@ def load_config() -> dict[str, Any] | None:
4547

4648
if config_path.name == "pyproject.toml":
4749
return config.get("tool", {}).get("griffe2md", None)
48-
return config
50+
return typing.cast(rendering.ConfigDict, config)

src/griffe2md/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _output(text: str, to: IO | str | None = None) -> None:
2727
to.write(text)
2828

2929

30-
def prepare_context(obj: Object, config: dict | None = None) -> dict:
30+
def prepare_context(obj: Object, config: rendering.ConfigDict | None = None) -> dict:
3131
"""Prepare Jinja context.
3232
3333
Parameters:
@@ -37,7 +37,7 @@ def prepare_context(obj: Object, config: dict | None = None) -> dict:
3737
Returns:
3838
The Jinja context.
3939
"""
40-
config = dict(rendering.default_config, **(config or {}))
40+
config = rendering.ConfigDict(rendering.default_config, **(config or {}))
4141
if config["filters"]:
4242
config["filters"] = [(re.compile(filtr.lstrip("!")), filtr.startswith("!")) for filtr in config["filters"]]
4343

@@ -113,7 +113,7 @@ def prepare_env(env: Environment | None = None) -> Environment:
113113
return env
114114

115115

116-
def render_object_docs(obj: Object, config: dict | None = None) -> str:
116+
def render_object_docs(obj: Object, config: rendering.ConfigDict | None = None) -> str:
117117
"""Render docs for a given object.
118118
119119
Parameters:
@@ -129,7 +129,7 @@ def render_object_docs(obj: Object, config: dict | None = None) -> str:
129129
return mdformat.text(rendered)
130130

131131

132-
def render_package_docs(package: str, config: dict | None = None) -> str:
132+
def render_package_docs(package: str, config: rendering.ConfigDict | None = None) -> str:
133133
"""Render docs for a given package.
134134
135135
Parameters:
@@ -147,7 +147,7 @@ def render_package_docs(package: str, config: dict | None = None) -> str:
147147
return render_object_docs(module, config) # type: ignore[arg-type]
148148

149149

150-
def write_package_docs(package: str, config: dict | None = None, output: IO | str | None = None) -> None:
150+
def write_package_docs(package: str, config: rendering.ConfigDict | None = None, output: IO | str | None = None) -> None:
151151
"""Write docs for a given package to a file or stdout.
152152
153153
Parameters:

src/griffe2md/rendering.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import string
1010
import sys
11+
import typing
1112
from functools import lru_cache, partial
1213
from re import Pattern
1314
from typing import TYPE_CHECKING, Any, Callable
@@ -46,7 +47,54 @@ class Order(enum.Enum):
4647
"""Source code order."""
4748

4849

49-
default_config: dict = {
50+
class ConfigDict(typing.TypedDict):
51+
"""Configuration for griffe2md, griffe and mkdocstrings"""
52+
53+
allow_inspection: bool
54+
annotations_path: str
55+
docstring_options: dict
56+
"""mkdocstring [configuration](https://mkdocstrings.github.io/python/usage/configuration/general/)"""
57+
58+
docstring_section_style: str
59+
docstring_style: str
60+
"""Style of project docstring. Supported options are: 'auto', 'google', 'numpy' or 'sphinx'"""
61+
62+
filters: Any
63+
group_by_category: bool
64+
heading_level: int
65+
inherited_members: bool
66+
line_length: int
67+
load_external_modules: bool
68+
members: Any
69+
members_order: Any
70+
merge_init_into_class: bool
71+
preload_modules: Any
72+
separate_signature: bool
73+
show_bases: bool
74+
show_category_heading: bool
75+
show_docstring_attributes: bool
76+
show_docstring_description: bool
77+
show_docstring_examples: bool
78+
show_docstring_other_parameters: bool
79+
show_docstring_parameters: bool
80+
show_docstring_raises: bool
81+
show_docstring_receives: bool
82+
show_docstring_returns: bool
83+
show_docstring_warns: bool
84+
show_docstring_yields: bool
85+
show_if_no_docstring: bool
86+
show_object_full_path: bool
87+
show_root_full_path: bool
88+
show_root_heading: bool
89+
show_root_members_full_path: bool
90+
show_signature: bool
91+
show_signature_annotations: bool
92+
show_submodules: bool
93+
signature_crossrefs: bool
94+
summary: bool
95+
96+
97+
default_config: ConfigDict = {
5098
"docstring_style": "google",
5199
"docstring_options": {"ignore_init_summary": True},
52100
"show_root_heading": True,

0 commit comments

Comments
 (0)