| 1 |
# General options |
| 2 |
|
| 3 |
[](){#option-allow_inspection} |
| 4 |
## `allow_inspection` |
| 5 |
|
| 6 |
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** |
| 7 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) --> |
| 8 |
|
| 9 |
Whether to allow inspecting modules (importing them) |
| 10 |
when it is not possible to visit them (parse their source code). |
| 11 |
|
| 12 |
When loading data for a given package, [Griffe] discovers every Python module, |
| 13 |
compiled or not, and inspects or visits them accordingly. |
| 14 |
|
| 15 |
If you have compiled modules but also provide stubs for them, |
| 16 |
you might want to disable the inspection of these modules, |
| 17 |
because inspection picks up many more members, |
| 18 |
and sometimes the collected data is inaccurate |
| 19 |
(depending on the tool that was used to compile the module) |
| 20 |
or too low-level/technical for API documentation. |
| 21 |
|
| 22 |
See also [`force_inspection`](#force_inspection). |
| 23 |
|
| 24 |
WARNING: **Packages are loaded only once.** When mkdocstrings-python collects data from a Python package (thanks to [Griffe](https://mkdocstrings.github.io/griffe/)), it collects *the entire package* and *caches it*. Next time an object from the same package is rendered, the package is retrieved from the cache and not collected again. The `allow_inspection` option will therefore only have an effect the first time a package is collected, and will do nothing for objects rendered afterwards. |
| 25 |
|
| 26 |
```yaml title="in mkdocs.yml (global configuration)" |
| 27 |
plugins: |
| 28 |
- mkdocstrings: |
| 29 |
handlers: |
| 30 |
python: |
| 31 |
options: |
| 32 |
allow_inspection: true |
| 33 |
``` |
| 34 |
|
| 35 |
```md title="or in docs/some_page.md (local configuration)" |
| 36 |
::: path.to.object |
| 37 |
options: |
| 38 |
allow_inspection: false |
| 39 |
``` |
| 40 |
|
| 41 |
/// admonition | Preview |
| 42 |
type: preview |
| 43 |
|
| 44 |
//// tab | With inspection |
| 45 |
<h2><code>SomeClass</code></h2> |
| 46 |
<p>Docstring of the class.</p> |
| 47 |
<h3><code>__eq__</code></h3> |
| 48 |
<p>Method docstring.</p> |
| 49 |
<h3><code>__weakref__</code></h3> |
| 50 |
<p>Method docstring.</p> |
| 51 |
<h3><code>documented_method</code></h3> |
| 52 |
<p>Method docstring.</p> |
| 53 |
//// |
| 54 |
|
| 55 |
//// tab | Without inspection |
| 56 |
<h2><code>SomeClass</code></h2> |
| 57 |
<p>Docstring of the class.</p> |
| 58 |
<h3><code>documented_method</code></h3> |
| 59 |
<p>Method docstring.</p> |
| 60 |
//// |
| 61 |
/// |
| 62 |
|
| 63 |
[](){#option-backlinks} |
| 64 |
## `backlinks` |
| 65 |
|
| 66 |
- **:octicons-package-24: Type <code><autoref identifier="typing.Literal" optional>Literal</autoref>\["flat", "tree", False\]</code> :material-equal: `False`{ title="default value" }** |
| 67 |
|
| 68 |
The `backlinks` option enables rendering of backlinks within your API documentation. |
| 69 |
|
| 70 |
When an arbitrary section of your documentation links to an API symbol, this link will be collected as a backlink, and rendered below your API symbol. In short, the API symbol will link back to the section that links to it. Such backlinks will help your users navigate the documentation, as they will immediately which functions return a specific symbol, or where a specific symbol is accepted as parameter, etc.. |
| 71 |
|
| 72 |
Each backlink is a list of breadcrumbs that represent the navigation, from the root page down to the given section. |
| 73 |
|
| 74 |
The available styles for rendering backlinks are **`flat`** and **`tree`**. |
| 75 |
|
| 76 |
- **`flat`** will render backlinks as a single-layer list. This can lead to repetition of breadcrumbs. |
| 77 |
- **`tree`** will combine backlinks into a tree, to remove repetition of breadcrumbs. |
| 78 |
|
| 79 |
WARNING: **Global-only option.** For now, the option only works when set globally in `mkdocs.yml`. |
| 80 |
|
| 81 |
```yaml title="in mkdocs.yml (global configuration)" |
| 82 |
plugins: |
| 83 |
- mkdocstrings: |
| 84 |
handlers: |
| 85 |
python: |
| 86 |
options: |
| 87 |
backlinks: tree |
| 88 |
``` |
| 89 |
|
| 90 |
/// admonition | Preview |
| 91 |
type: preview |
| 92 |
|
| 93 |
//// tab | Flat |
| 94 |
 |
| 95 |
//// |
| 96 |
|
| 97 |
//// tab | Tree |
| 98 |
 |
| 99 |
//// |
| 100 |
/// |
| 101 |
|
| 102 |
[](){#option-extensions} |
| 103 |
## `extensions` |
| 104 |
|
| 105 |
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>\[<autoref identifier="str" optional>str</autoref> | <autoref identifier="dict" optional>dict</autoref>\[<autoref identifier="str" optional>str</autoref>, <autoref identifier="dict" optional>dict</autoref>\[<autoref identifier="str" optional>str</autoref>, <autoref identifier="typing.Any" optional>Any</autoref>\]\]\]</code> :material-equal: `[]`{ title="default value" }** |
| 106 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) --> |
| 107 |
|
| 108 |
The `extensions` option lets you enable [Griffe extensions](https://mkdocstrings.github.io/griffe/extensions/), which enhance or modify the data collected from Python sources (or compiled modules). |
| 109 |
|
| 110 |
Elements in the list can be strings or dictionaries. |
| 111 |
|
| 112 |
Strings denote the path to an extension module, like `griffe_typingdoc`, or to an extension class directly, like `griffe_typingdoc.TypingDocExtension`. When using a module path, all extensions within that module will be loaded and enabled. Strings can also be the path to a Python module, and a class name separated with `:`, like `scripts/griffe_extensions.py` or `scripts/griffe_extensions.py:MyExtension`. |
| 113 |
|
| 114 |
Dictionaries have a single key, which is the module/class path (as a dot-separated qualifier or file path and colon-separated class name, like above), and its value is another dictionary specifying options that will be passed when to class constructors when instantiating extensions. |
| 115 |
|
| 116 |
WARNING: **Packages are loaded only once.** When mkdocstrings-python collects data from a Python package (thanks to [Griffe](https://mkdocstrings.github.io/griffe/)), it collects *the entire package* and *caches it*. Next time an object from the same package is rendered, the package is retrieved from the cache and not collected again. Only the extensions specified the first time the package is loaded will be used. You cannot use a different set of extensions for specific objects rendered afterwards, and you cannot deactivate extensions for objects rendered afterwards either. |
| 117 |
|
| 118 |
```yaml title="in mkdocs.yml (global configuration)" |
| 119 |
plugins: |
| 120 |
- mkdocstrings: |
| 121 |
handlers: |
| 122 |
python: |
| 123 |
options: |
| 124 |
extensions: |
| 125 |
- griffe_sphinx |
| 126 |
- griffe_pydantic: {schema: true} |
| 127 |
- scripts/exts.py:DynamicDocstrings: |
| 128 |
paths: [mypkg.mymod.myobj] |
| 129 |
``` |
| 130 |
|
| 131 |
```md title="or in docs/some_page.md (local configuration)" |
| 132 |
::: your_package.your_module.your_func |
| 133 |
options: |
| 134 |
extensions: |
| 135 |
- griffe_typingdoc |
| 136 |
``` |
| 137 |
|
| 138 |
[](){#option-extra} |
| 139 |
## `extra` |
| 140 |
|
| 141 |
- **:octicons-package-24: Type [`dict`][] :material-equal: `{}`{ title="default value" }** |
| 142 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) --> |
| 143 |
|
| 144 |
The `extra` option lets you inject additional variables into the Jinja context used when rendering templates. You can then use this extra context in your [overridden templates][templates]. |
| 145 |
|
| 146 |
Local `extra` options will be merged into the global `extra` option: |
| 147 |
|
| 148 |
```yaml title="in mkdocs.yml (global configuration)" |
| 149 |
plugins: |
| 150 |
- mkdocstrings: |
| 151 |
handlers: |
| 152 |
python: |
| 153 |
options: |
| 154 |
extra: |
| 155 |
hello: world |
| 156 |
``` |
| 157 |
|
| 158 |
```md title="in docs/some_page.md (local configuration)" |
| 159 |
::: your_package.your_module.your_func |
| 160 |
options: |
| 161 |
extra: |
| 162 |
foo: bar |
| 163 |
``` |
| 164 |
|
| 165 |
...will inject both `hello` and `foo` into the Jinja context when rendering `your_package.your_module.your_func`. |
| 166 |
|
| 167 |
> WARNING: Previously, extra options were supported directly under the `options` key. |
| 168 |
> |
| 169 |
> ```yaml |
| 170 |
> plugins: |
| 171 |
> - mkdocstrings: |
| 172 |
> handlers: |
| 173 |
> python: |
| 174 |
> options: |
| 175 |
> hello: world |
| 176 |
> ``` |
| 177 |
> |
| 178 |
> Now that we introduced optional validation of options and automatic JSON schema generation thanks to Pydantic, we require extra options to be put under `options.extra`. Extra options directly under `options` are still supported, but deprecated, and will emit deprecation warnings. Support will be removed in a future version of mkdocstrings-python. |
| 179 |
|
| 180 |
[](){#option-find_stubs_package} |
| 181 |
## `find_stubs_package` |
| 182 |
|
| 183 |
- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** |
| 184 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) --> |
| 185 |
|
| 186 |
When looking for documentation specified in [autodoc instructions][autodoc syntax] (`::: identifier`), also look for |
| 187 |
the stubs package as defined in [PEP 561](https://peps.python.org/pep-0561/) if it exists. This is useful when |
| 188 |
most of your documentation is separately provided by such a package and not inline in your main package. |
| 189 |
|
| 190 |
WARNING: **Packages are loaded only once.** When mkdocstrings-python collects data from a Python package (thanks to [Griffe](https://mkdocstrings.github.io/griffe/)), it collects *the entire package* and *caches it*. Next time an object from the same package is rendered, the package is retrieved from the cache and not collected again. The `find_stubs_package` option will therefore only have an effect the first time a package is collected, and will do nothing for objects rendered afterwards. |
| 191 |
|
| 192 |
```yaml title="in mkdocs.yml (global configuration)" |
| 193 |
plugins: |
| 194 |
- mkdocstrings: |
| 195 |
handlers: |
| 196 |
python: |
| 197 |
options: |
| 198 |
find_stubs_package: true |
| 199 |
``` |
| 200 |
|
| 201 |
```md title="or in docs/some_page.md (local configuration)" |
| 202 |
::: your_package.your_module.your_func |
| 203 |
options: |
| 204 |
find_stubs_package: true |
| 205 |
``` |
| 206 |
|
| 207 |
```python title="your_package/your_module.py" |
| 208 |
|
| 209 |
def your_func(a, b): |
| 210 |
# Function code |
| 211 |
... |
| 212 |
|
| 213 |
# rest of your code |
| 214 |
``` |
| 215 |
|
| 216 |
```python title="your_package-stubs/your_module.pyi" |
| 217 |
|
| 218 |
def your_func(a: int, b: str): |
| 219 |
""" |
| 220 |
<Function docstring> |
| 221 |
""" |
| 222 |
... |
| 223 |
|
| 224 |
# rest of your code |
| 225 |
``` |
| 226 |
|
| 227 |
/// admonition | Preview |
| 228 |
type: preview |
| 229 |
|
| 230 |
//// tab | With find_stubs_package |
| 231 |
<h2><code>your_func</code></h2> |
| 232 |
<p>Function docstring</p> |
| 233 |
//// |
| 234 |
|
| 235 |
//// tab | Without find_stubs_package |
| 236 |
<h2><code>your_func</code></h2> |
| 237 |
//// |
| 238 |
/// |
| 239 |
|
| 240 |
[](){#option-force_inspection} |
| 241 |
## `force_inspection` |
| 242 |
|
| 243 |
- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** |
| 244 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) --> |
| 245 |
|
| 246 |
Whether to force inspecting modules (importing them) even if their source code is available. |
| 247 |
|
| 248 |
This option is useful when you know that dynamic analysis (inspection) yields better results than static analysis. Do not use this blindly: the recommended approach is to write a Griffe extension that will improve extracted API data. See [How to selectively inspect objects](https://mkdocstrings.github.io/griffe/guide/users/how-to/selectively-inspect/). |
| 249 |
|
| 250 |
See also [`allow_inspection`](#allow_inspection). |
| 251 |
|
| 252 |
```yaml title="in mkdocs.yml (global configuration)" |
| 253 |
plugins: |
| 254 |
- mkdocstrings: |
| 255 |
handlers: |
| 256 |
python: |
| 257 |
options: |
| 258 |
force_inspection: false |
| 259 |
``` |
| 260 |
|
| 261 |
```md title="or in docs/some_page.md (local configuration)" |
| 262 |
::: path.to.object |
| 263 |
options: |
| 264 |
force_inspection: true |
| 265 |
``` |
| 266 |
|
| 267 |
WARNING: **Packages are loaded only once.** When mkdocstrings-python collects data from a Python package (thanks to [Griffe](https://mkdocstrings.github.io/griffe/)), it collects *the entire package* and *caches it*. Next time an object from the same package is rendered, the package is retrieved from the cache and not collected again. The `force_inspection` option will therefore only have an effect the first time a package is collected, and will do nothing for objects rendered afterwards. |
| 268 |
|
| 269 |
[](){#option-inheritance_diagram_direction} |
| 270 |
## `inheritance_diagram_direction` |
| 271 |
|
| 272 |
The direction of the Mermaid chart presenting the inheritance diagram of a class, `TD` by default. |
| 273 |
|
| 274 |
```yaml title="mkdocs.yml" |
| 275 |
extra_javascript: |
| 276 |
- https://unpkg.com/[email protected]/dist/mermaid.min.js |
| 277 |
``` |
| 278 |
|
| 279 |
```yaml title="in mkdocs.yml (global configuration)" |
| 280 |
plugins: |
| 281 |
- mkdocstrings: |
| 282 |
handlers: |
| 283 |
python: |
| 284 |
options: |
| 285 |
inheritance_diagram_direction: TD |
| 286 |
``` |
| 287 |
|
| 288 |
```md title="or in docs/some_page.md (local configuration)" |
| 289 |
::: path.to.object |
| 290 |
options: |
| 291 |
inheritance_diagram_direction: TD |
| 292 |
``` |
| 293 |
|
| 294 |
/// admonition | Preview |
| 295 |
type: preview |
| 296 |
|
| 297 |
|
| 298 |
With the following classes: |
| 299 |
|
| 300 |
```python |
| 301 |
class SuperAbstract: |
| 302 |
"""Super abstract class.""" |
| 303 |
class Mixin1: |
| 304 |
"""Mixin 1.""" |
| 305 |
class Abstract(SuperAbstract, Mixin1): |
| 306 |
"""Abstract class.""" |
| 307 |
class Mixin2A: |
| 308 |
"""Mixin 2A.""" |
| 309 |
class Mixin2B(Mixin2A): |
| 310 |
"""Mixin 2B.""" |
| 311 |
class Concrete(Abstract, Mixin2B): |
| 312 |
"""Concrete class.""" |
| 313 |
class SuperConcrete(Concrete): |
| 314 |
"""Super concrete class.""" |
| 315 |
``` |
| 316 |
|
| 317 |
//// tab | `TD` (or `TB`) |
| 318 |
|
| 319 |
```mermaid |
| 320 |
flowchart TD |
| 321 |
SuperConcrete[SuperConcrete] |
| 322 |
Concrete[Concrete] |
| 323 |
Abstract[Abstract] |
| 324 |
SuperAbstract[SuperAbstract] |
| 325 |
Mixin1[Mixin1] |
| 326 |
Mixin2B[Mixin2B] |
| 327 |
Mixin2A[Mixin2A] |
| 328 |
|
| 329 |
Concrete --> SuperConcrete |
| 330 |
Abstract --> Concrete |
| 331 |
SuperAbstract --> Abstract |
| 332 |
Mixin1 --> Abstract |
| 333 |
Mixin2B --> Concrete |
| 334 |
Mixin2A --> Mixin2B |
| 335 |
``` |
| 336 |
|
| 337 |
//// |
| 338 |
|
| 339 |
//// tab | `BT` |
| 340 |
|
| 341 |
```mermaid |
| 342 |
flowchart BT |
| 343 |
SuperConcrete[SuperConcrete] |
| 344 |
Concrete[Concrete] |
| 345 |
Abstract[Abstract] |
| 346 |
SuperAbstract[SuperAbstract] |
| 347 |
Mixin1[Mixin1] |
| 348 |
Mixin2B[Mixin2B] |
| 349 |
Mixin2A[Mixin2A] |
| 350 |
|
| 351 |
Concrete --> SuperConcrete |
| 352 |
Abstract --> Concrete |
| 353 |
SuperAbstract --> Abstract |
| 354 |
Mixin1 --> Abstract |
| 355 |
Mixin2B --> Concrete |
| 356 |
Mixin2A --> Mixin2B |
| 357 |
``` |
| 358 |
|
| 359 |
//// |
| 360 |
|
| 361 |
//// tab | `RL` |
| 362 |
|
| 363 |
```mermaid |
| 364 |
flowchart RL |
| 365 |
SuperConcrete[SuperConcrete] |
| 366 |
Concrete[Concrete] |
| 367 |
Abstract[Abstract] |
| 368 |
SuperAbstract[SuperAbstract] |
| 369 |
Mixin1[Mixin1] |
| 370 |
Mixin2B[Mixin2B] |
| 371 |
Mixin2A[Mixin2A] |
| 372 |
|
| 373 |
Concrete --> SuperConcrete |
| 374 |
Abstract --> Concrete |
| 375 |
SuperAbstract --> Abstract |
| 376 |
Mixin1 --> Abstract |
| 377 |
Mixin2B --> Concrete |
| 378 |
Mixin2A --> Mixin2B |
| 379 |
``` |
| 380 |
|
| 381 |
//// |
| 382 |
|
| 383 |
//// tab | `LR` |
| 384 |
|
| 385 |
```mermaid |
| 386 |
flowchart LR |
| 387 |
SuperConcrete[SuperConcrete] |
| 388 |
Concrete[Concrete] |
| 389 |
Abstract[Abstract] |
| 390 |
SuperAbstract[SuperAbstract] |
| 391 |
Mixin1[Mixin1] |
| 392 |
Mixin2B[Mixin2B] |
| 393 |
Mixin2A[Mixin2A] |
| 394 |
|
| 395 |
Concrete --> SuperConcrete |
| 396 |
Abstract --> Concrete |
| 397 |
SuperAbstract --> Abstract |
| 398 |
Mixin1 --> Abstract |
| 399 |
Mixin2B --> Concrete |
| 400 |
Mixin2A --> Mixin2B |
| 401 |
``` |
| 402 |
|
| 403 |
//// |
| 404 |
/// |
| 405 |
|
| 406 |
[](){#option-preload_modules} |
| 407 |
## `preload_modules` |
| 408 |
|
| 409 |
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>\[<autoref identifier="str" optional>str</autoref>\] | None</code> :material-equal: `None`{ title="default value" }** |
| 410 |
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) --> |
| 411 |
|
| 412 |
Pre-load modules that are not specified directly in [autodoc instructions][autodoc syntax] (`::: identifier`). |
| 413 |
It is useful when you want to render documentation for a particular member of an object, |
| 414 |
and this member is imported from another package than its parent. |
| 415 |
|
| 416 |
For an imported member to be rendered, |
| 417 |
you need to add it to the [`__all__`][__all__] attribute of the importing module. |
| 418 |
The package from which the imported object originates must be accessible to the handler |
| 419 |
(see [Finding modules](../index.md#finding-modules)). |
| 420 |
|
| 421 |
```yaml title="in mkdocs.yml (global configuration)" |
| 422 |
plugins: |
| 423 |
- mkdocstrings: |
| 424 |
handlers: |
| 425 |
python: |
| 426 |
options: |
| 427 |
preload_modules: |
| 428 |
- their_package |
| 429 |
``` |
| 430 |
|
| 431 |
```md title="or in docs/some_page.md (local configuration)" |
| 432 |
::: your_package.your_module |
| 433 |
options: |
| 434 |
preload_modules: |
| 435 |
- their_package |
| 436 |
``` |
| 437 |
|
| 438 |
```python title="your_package/your_module.py" |
| 439 |
from their_package.their_module import their_object |
| 440 |
|
| 441 |
__all__ = ["their_object"] |
| 442 |
|
| 443 |
# rest of your code |
| 444 |
``` |
| 445 |
|
| 446 |
/// admonition | Preview |
| 447 |
type: preview |
| 448 |
|
| 449 |
//// tab | With preloaded modules |
| 450 |
<h2><code>your_module</code></h2> |
| 451 |
<p>Docstring of your module.</p> |
| 452 |
<h3><code>their_object</code></h3> |
| 453 |
<p>Docstring of their object.</p> |
| 454 |
//// |
| 455 |
|
| 456 |
//// tab | Without preloaded modules |
| 457 |
<h2><code>your_module</code></h2> |
| 458 |
<p>Docstring of your module.</p> |
| 459 |
//// |
| 460 |
/// |
| 461 |
|
| 462 |
[](){#option-show_bases} |
| 463 |
## `show_bases` |
| 464 |
|
| 465 |
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** |
| 466 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) --> |
| 467 |
|
| 468 |
Show the base classes of a class. |
| 469 |
|
| 470 |
```yaml title="in mkdocs.yml (global configuration)" |
| 471 |
plugins: |
| 472 |
- mkdocstrings: |
| 473 |
handlers: |
| 474 |
python: |
| 475 |
options: |
| 476 |
show_bases: true |
| 477 |
``` |
| 478 |
|
| 479 |
```md title="or in docs/some_page.md (local configuration)" |
| 480 |
::: path.to.object |
| 481 |
options: |
| 482 |
show_bases: false |
| 483 |
``` |
| 484 |
|
| 485 |
/// admonition | Preview |
| 486 |
type: preview |
| 487 |
|
| 488 |
//// tab | With bases |
| 489 |
<h2><code>SomeClass()</code></h2> |
| 490 |
<p>Bases: <code><a href="#with">SomeBaseClass</a></code></p> |
| 491 |
<p>Docstring of the class.</p> |
| 492 |
//// |
| 493 |
|
| 494 |
//// tab | Without bases |
| 495 |
<h2><code>SomeClass()</code></h2> |
| 496 |
<p>Docstring of the class.</p> |
| 497 |
//// |
| 498 |
/// |
| 499 |
|
| 500 |
[](){#option-show_inheritance_diagram} |
| 501 |
## `show_inheritance_diagram` |
| 502 |
|
| 503 |
- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** |
| 504 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) --> |
| 505 |
|
| 506 |
Show the inheritance diagram of a class using [Mermaid](https://mermaid.js.org/). |
| 507 |
|
| 508 |
With this option enabled, an inheritance diagram (as a flowchart) |
| 509 |
will be displayed after a class signature. |
| 510 |
Each node will act as a cross-reference |
| 511 |
and will bring you to the relevant class' documentation |
| 512 |
when clicking on it. |
| 513 |
|
| 514 |
It should work out of the box with [Material for MkDocs][]. |
| 515 |
For other themes, you must include Mermaid's Javascript code manually: |
| 516 |
|
| 517 |
```yaml title="mkdocs.yml" |
| 518 |
extra_javascript: |
| 519 |
- https://unpkg.com/[email protected]/dist/mermaid.min.js |
| 520 |
``` |
| 521 |
|
| 522 |
```yaml title="in mkdocs.yml (global configuration)" |
| 523 |
plugins: |
| 524 |
- mkdocstrings: |
| 525 |
handlers: |
| 526 |
python: |
| 527 |
options: |
| 528 |
show_inheritance_diagram: true |
| 529 |
``` |
| 530 |
|
| 531 |
```md title="or in docs/some_page.md (local configuration)" |
| 532 |
::: path.to.object |
| 533 |
options: |
| 534 |
show_inheritance_diagram: false |
| 535 |
``` |
| 536 |
|
| 537 |
/// admonition | Preview |
| 538 |
type: preview |
| 539 |
|
| 540 |
With the following classes: |
| 541 |
|
| 542 |
```python |
| 543 |
class SuperAbstract: |
| 544 |
"""Super abstract class.""" |
| 545 |
class Mixin1: |
| 546 |
"""Mixin 1.""" |
| 547 |
class Abstract(SuperAbstract, Mixin1): |
| 548 |
"""Abstract class.""" |
| 549 |
class Mixin2A: |
| 550 |
"""Mixin 2A.""" |
| 551 |
class Mixin2B(Mixin2A): |
| 552 |
"""Mixin 2B.""" |
| 553 |
class Concrete(Abstract, Mixin2B): |
| 554 |
"""Concrete class.""" |
| 555 |
class SuperConcrete(Concrete): |
| 556 |
"""Super concrete class.""" |
| 557 |
``` |
| 558 |
|
| 559 |
The diagram for `SuperConcrete` will look like this: |
| 560 |
|
| 561 |
```mermaid |
| 562 |
flowchart TD |
| 563 |
SuperConcrete[SuperConcrete] |
| 564 |
Concrete[Concrete] |
| 565 |
Abstract[Abstract] |
| 566 |
SuperAbstract[SuperAbstract] |
| 567 |
Mixin1[Mixin1] |
| 568 |
Mixin2B[Mixin2B] |
| 569 |
Mixin2A[Mixin2A] |
| 570 |
|
| 571 |
Concrete --> SuperConcrete |
| 572 |
Abstract --> Concrete |
| 573 |
SuperAbstract --> Abstract |
| 574 |
Mixin1 --> Abstract |
| 575 |
Mixin2B --> Concrete |
| 576 |
Mixin2A --> Mixin2B |
| 577 |
``` |
| 578 |
|
| 579 |
*Nodes are not clickable in this example |
| 580 |
because these classes do not exist in our documentation.* |
| 581 |
/// |
| 582 |
|
| 583 |
[](){#option-show_source} |
| 584 |
## `show_source` |
| 585 |
|
| 586 |
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** |
| 587 |
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template] and [`function.html`][function template]) --> |
| 588 |
|
| 589 |
Show the source code of this object. |
| 590 |
|
| 591 |
```yaml title="in mkdocs.yml (global configuration)" |
| 592 |
plugins: |
| 593 |
- mkdocstrings: |
| 594 |
handlers: |
| 595 |
python: |
| 596 |
options: |
| 597 |
show_source: true |
| 598 |
``` |
| 599 |
|
| 600 |
```md title="or in docs/some_page.md (local configuration)" |
| 601 |
::: path.to.object |
| 602 |
options: |
| 603 |
show_source: false |
| 604 |
``` |
| 605 |
|
| 606 |
/// admonition | Preview |
| 607 |
type: preview |
| 608 |
|
| 609 |
//// tab | With source |
| 610 |
<h2><code>some_function()</code></h2> |
| 611 |
<p>Docstring of the function.</p> |
| 612 |
|
| 613 |
///// details | Source code in `package/module.py` |
| 614 |
type: quote |
| 615 |
|
| 616 |
```python linenums="1" |
| 617 |
def some_function(): |
| 618 |
... |
| 619 |
``` |
| 620 |
///// |
| 621 |
//// |
| 622 |
|
| 623 |
//// tab | Without source |
| 624 |
<h2><code>some_function()</code></h2> |
| 625 |
<p>Docstring of the function.</p> |
| 626 |
//// |
| 627 |
/// |
| 628 |
|
| 629 |
[](){#option-skip_local_inventory} |
| 630 |
## `skip_local_inventory` |
| 631 |
|
| 632 |
- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** |
| 633 |
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) --> |
| 634 |
|
| 635 |
Whether to skip registering symbols in the objects inventory. |
| 636 |
|
| 637 |
With this option enabled, re-rendering docstrings for objects from external inventories is possible with their cross-references pointing to the original external inventory, not local. Similarly, it becomes possible to render the same symbol several times in the same documentation, with only one canonical location being used for cross-references (preventing confusion in mkdocs-autorefs). |
| 638 |
|
| 639 |
```yaml title="in mkdocs.yml (global configuration)" |
| 640 |
plugins: |
| 641 |
- mkdocstrings: |
| 642 |
handlers: |
| 643 |
python: |
| 644 |
options: |
| 645 |
skip_local_inventory: false |
| 646 |
``` |
| 647 |
|
| 648 |
```md title="or in docs/some_page.md (local configuration)" |
| 649 |
::: path.to.module |
| 650 |
options: |
| 651 |
skip_local_inventory: true |
| 652 |
``` |
| 653 |
|
| 654 |
/// admonition | Preview |
| 655 |
type: preview |
| 656 |
|
| 657 |
|
| 658 |
//// tab | Without `skip_local_inventory` |
| 659 |
|
| 660 |
```md exec="on" |
| 661 |
::: bisect.bisect_left |
| 662 |
options: |
| 663 |
heading_level: 3 |
| 664 |
skip_local_inventory: false |
| 665 |
show_docstring_description: false |
| 666 |
``` |
| 667 |
|
| 668 |
Notice how [`bisect.bisect_left`][] now points to the section above. |
| 669 |
|
| 670 |
//// |
| 671 |
|
| 672 |
//// tab | With `skip_local_inventory` |
| 673 |
|
| 674 |
```md exec="on" |
| 675 |
::: bisect.bisect_right |
| 676 |
inventories: |
| 677 |
- https://docs.python.org/3/objects.inv |
| 678 |
options: |
| 679 |
heading_level: 3 |
| 680 |
skip_local_inventory: true |
| 681 |
show_docstring_description: false |
| 682 |
``` |
| 683 |
|
| 684 |
Notice how [`bisect.bisect_right`][] points to the original Python documentation. |
| 685 |
|
| 686 |
//// |
| 687 |
/// |