Skip to content

Commit f2eee9a

Browse files
committed
Merge branch 'master' of github.com:mkdocstrings/python
2 parents 9164742 + a6c55fb commit f2eee9a

File tree

10 files changed

+144
-40
lines changed

10 files changed

+144
-40
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
<!-- insertion marker -->
8+
## [0.8.3](https://github.com/mkdocstrings/python/releases/tag/0.8.3) - 2023-01-04
9+
10+
<small>[Compare with 0.8.2](https://github.com/mkdocstrings/python/compare/0.8.2...0.8.3)</small>
11+
12+
### Code Refactoring
13+
- Change "unresolved aliases" log level to DEBUG ([dccb818](https://github.com/mkdocstrings/python/commit/dccb818f51278cc8799e2187a615d999a3ab86fb) by Timothée Mazzucotelli).
14+
15+
816
## [0.8.2](https://github.com/mkdocstrings/python/releases/tag/0.8.2) - 2022-11-19
917

1018
<small>[Compare with 0.8.1](https://github.com/mkdocstrings/python/compare/0.8.1...0.8.2)</small>

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Our Pledge
44

55
In the interest of fostering an open and welcoming environment, we as
6-
contributors and maintainers pledge to making participation in our project and
6+
contributors and maintainers pledge to make participation in our project and
77
our community a harassment-free experience for everyone, regardless of age, body
88
size, disability, ethnicity, gender identity and expression, level of experience,
99
nationality, personal appearance, race, religion, or sexual identity and
@@ -39,7 +39,7 @@ response to any instances of unacceptable behavior.
3939

4040
Project maintainers have the right and responsibility to remove, edit, or
4141
reject comments, commits, code, wiki edits, issues, and other contributions
42-
that are not aligned to this Code of Conduct, or to ban temporarily or
42+
that are not aligned with this Code of Conduct, or to ban temporarily or
4343
permanently any contributor for other behaviors that they deem inappropriate,
4444
threatening, offensive, or harmful.
4545

@@ -58,7 +58,7 @@ Instances of abusive, harassing, or otherwise unacceptable behavior may be
5858
reported by contacting the project team at [email protected]. All
5959
complaints will be reviewed and investigated and will result in a response that
6060
is deemed necessary and appropriate to the circumstances. The project team is
61-
obligated to maintain confidentiality with regard to the reporter of an incident.
61+
obligated to maintain confidentiality concerning the reporter of an incident.
6262
Further details of specific enforcement policies may be posted separately.
6363

6464
Project maintainers who do not follow or enforce the Code of Conduct in good

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Scope and body are optional. Type can be:
9393
- `feat`: New feature.
9494
- `fix`: Bug fix.
9595
- `perf`: About performance.
96-
- `refactor`: Changes which are not features nor bug fixes.
96+
- `refactor`: Changes that are not features or bug fixes.
9797
- `style`: A change in code style/format.
9898
- `tests`: About tests.
9999

@@ -111,7 +111,7 @@ Fixes #15.
111111

112112
Link to any related issue in the Pull Request message.
113113

114-
During review, we recommend using fixups:
114+
During the review, we recommend using fixups:
115115

116116
```bash
117117
# SHA is the SHA of the commit you want to fix

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = [
3737
]
3838
```
3939

40-
You can also explicitely depend on the handler:
40+
You can also explicitly depend on the handler:
4141

4242
```toml title="pyproject.toml"
4343
# PEP 621 dependencies declaration
@@ -59,11 +59,11 @@ dependencies = [
5959
[Griffe](https://github.com/mkdocstrings/griffe).
6060

6161
- **Support for type annotations:** Griffe collects your type annotations and *mkdocstrings* uses them
62-
to display parameters types or return types. It is even able to automatically add cross-references
63-
to other objects from your API, from the standard library or from third-party libraries!
62+
to display parameter types or return types. It is even able to automatically add cross-references
63+
to other objects from your API, from the standard library or third-party libraries!
6464
See [how to load inventories](https://mkdocstrings.github.io/usage/#cross-references-to-other-projects-inventories) to enable it.
6565

66-
- **Recursive documentation of Python objects:** just use the module dotted-path as identifier, and you get the full
66+
- **Recursive documentation of Python objects:** just use the module dotted-path as an identifier, and you get the full
6767
module docs. You don't need to inject documentation for each class, function, etc.
6868

6969
- **Support for documented attributes:** attributes (variables) followed by a docstring (triple-quoted string) will
@@ -77,7 +77,7 @@ dependencies = [
7777
*We do not support nested admonitions in docstrings!*
7878

7979
- **Every object has a TOC entry:** we render a heading for each object, meaning *MkDocs* picks them into the Table
80-
of Contents, which is nicely display by the Material theme. Thanks to *mkdocstrings* cross-reference ability,
80+
of Contents, which is nicely displayed by the Material theme. Thanks to *mkdocstrings* cross-reference ability,
8181
you can reference other objects within your docstrings, with the classic Markdown syntax:
8282
`[this object][package.module.object]` or directly with `[package.module.object][]`
8383

docs/customization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ See them [in the repository](https://github.com/mkdocstrings/python/tree/master/
124124
See the general *mkdocstrings* documentation to learn how to override them: https://mkdocstrings.github.io/theming/#templates.
125125

126126
In preparation for Jinja2 blocks, which will improve customization,
127-
each one of these templates extends in fact a base version in `theme/_base`. Example:
127+
each one of these templates extends a base version in `theme/_base`. Example:
128128

129129
```html+jinja title="theme/docstring/admonition.html"
130130
{% extends "_base/docstring/admonition.html" %}
@@ -139,7 +139,7 @@ each one of these templates extends in fact a base version in `theme/_base`. Exa
139139
```
140140

141141
It means you will be able to customize only *parts* of a template
142-
without having to fully copy-paste it in your project:
142+
without having to fully copy-paste it into your project:
143143

144144
```jinja title="templates/theme/docstring.html"
145145
{% extends "_base/docstring.html" %}

docs/schema.json

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
"base_url": {
2727
"title": "Base URL used to build references URLs.",
2828
"type": "string"
29+
},
30+
"domains": {
31+
"title": "Domains to import from the inventory.",
32+
"description": "If not defined it will only import 'py' domain.",
33+
"type": "array",
34+
"items": {
35+
"type": "string"
36+
}
2937
}
3038
}
3139
}
@@ -132,8 +140,68 @@
132140
"type": "boolean",
133141
"default": false
134142
},
143+
"show_docstring_attributes": {
144+
"title": "Whether to display the \"Attributes\" section in the object's docstring.",
145+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
146+
"type": "boolean",
147+
"default": true
148+
},
149+
"show_docstring_description": {
150+
"title": "Whether to display the textual block (including admonitions) in the object's docstring.",
151+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
152+
"type": "boolean",
153+
"default": true
154+
},
155+
"show_docstring_examples": {
156+
"title": "Whether to display the \"Examples\" section in the object's docstring.",
157+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
158+
"type": "boolean",
159+
"default": true
160+
},
161+
"show_docstring_other_parameters": {
162+
"title": "Whether to display the \"Other Parameters\" section in the object's docstring.",
163+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
164+
"type": "boolean",
165+
"default": true
166+
},
167+
"show_docstring_parameters": {
168+
"title": "Whether to display the \"Parameters\" section in the object's docstring.",
169+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
170+
"type": "boolean",
171+
"default": true
172+
},
173+
"show_docstring_raises": {
174+
"title": "Whether to display the \"Raises\" section in the object's docstring.",
175+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
176+
"type": "boolean",
177+
"default": true
178+
},
179+
"show_docstring_receives": {
180+
"title": "Whether to display the \"Receives\" section in the object's docstring.",
181+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
182+
"type": "boolean",
183+
"default": true
184+
},
185+
"show_docstring_returns": {
186+
"title": "Whether to display the \"Returns\" section in the object's docstring.",
187+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
188+
"type": "boolean",
189+
"default": true
190+
},
191+
"show_docstring_warns": {
192+
"title": "Whether to display the \"Warns\" section in the object's docstring.",
193+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
194+
"type": "boolean",
195+
"default": true
196+
},
197+
"show_docstring_yields": {
198+
"title": "Whether to display the \"Yields\" section in the object's docstring.",
199+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
200+
"type": "boolean",
201+
"default": true
202+
},
135203
"show_source": {
136-
"title": "Show the source code of this object..",
204+
"title": "Show the source code of this object.",
137205
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
138206
"type": "boolean",
139207
"default": true
@@ -203,4 +271,4 @@
203271
}
204272
},
205273
"additionalProperties": false
206-
}
274+
}

docs/usage.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ plugins:
7474
do_something: false
7575
```
7676

77-
These options affect how the documentation is collected from sources and renderered:
77+
These options affect how the documentation is collected from sources and rendered:
7878
headings, members, docstrings, etc.
7979

8080
::: mkdocstrings_handlers.python.handler.PythonHandler.default_config
@@ -202,7 +202,7 @@ TIP: **This is the recommended method.**
202202
```
203203

204204
Except for case 1, which is supported by default, **we strongly recommend
205-
to set the path to your packages using this option, even if it works without it**
205+
setting the path to your packages using this option, even if it works without it**
206206
(for example because your project manager automatically adds `src` to PYTHONPATH),
207207
to make sure anyone can build your docs from any location on their filesystem.
208208

@@ -211,7 +211,7 @@ to make sure anyone can build your docs from any location on their filesystem.
211211
WARNING: **This method has limitations.**
212212
This method might work for you, with your current setup,
213213
but not for others trying your build your docs with their own setup/environment.
214-
We recommend to use the [`paths` method](#using-the-paths-option) instead.
214+
We recommend using the [`paths` method](#using-the-paths-option) instead.
215215

216216
You can take advantage of the usual Python loading mechanisms.
217217
In Bash and other shells, you can run your command like this
@@ -270,7 +270,7 @@ In Bash and other shells, you can run your command like this
270270
WARNING: **This method has limitations.**
271271
This method might work for you, with your current setup,
272272
but not for others trying your build your docs with their own setup/environment.
273-
We recommend to use the [`paths` method](#using-the-paths-option) instead.
273+
We recommend using the [`paths` method](#using-the-paths-option) instead.
274274

275275
Install your package in the current environment, and run MkDocs:
276276

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
"Typing :: Typed",
3030
]
3131
dependencies = [
32-
"mkdocstrings>=0.19",
32+
"mkdocstrings>=0.20",
3333
"griffe>=0.24",
3434
]
3535

@@ -98,7 +98,7 @@ tests = [
9898
"pytest-xdist>=2.4",
9999
]
100100
typing = [
101-
"mypy>=0.910",
101+
"mypy>=0.911",
102102
"types-markdown>=3.3",
103103
"types-toml>=0.10",
104104
]

src/mkdocstrings_handlers/python/handler.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from __future__ import annotations
44

5+
import copy
56
import glob
67
import os
78
import posixpath
89
import re
910
import sys
1011
from collections import ChainMap
1112
from contextlib import suppress
12-
from typing import Any, BinaryIO, Iterator, Optional, Tuple
13+
from typing import Any, BinaryIO, Iterator, Mapping, Optional, Tuple
1314

1415
from griffe.agents.extensions import load_extensions
1516
from griffe.collections import LinesCollection, ModulesCollection
@@ -78,6 +79,16 @@ class PythonHandler(BaseHandler):
7879
"separate_signature": False,
7980
"line_length": 60,
8081
"merge_init_into_class": False,
82+
"show_docstring_attributes": True,
83+
"show_docstring_description": True,
84+
"show_docstring_examples": True,
85+
"show_docstring_other_parameters": True,
86+
"show_docstring_parameters": True,
87+
"show_docstring_raises": True,
88+
"show_docstring_receives": True,
89+
"show_docstring_returns": True,
90+
"show_docstring_warns": True,
91+
"show_docstring_yields": True,
8192
"show_source": True,
8293
"show_bases": True,
8394
"show_submodules": False,
@@ -118,6 +129,16 @@ class PythonHandler(BaseHandler):
118129
line_length (int): Maximum line length when formatting code/signatures. Default: `60`.
119130
merge_init_into_class (bool): Whether to merge the `__init__` method into the class' signature and docstring. Default: `False`.
120131
show_if_no_docstring (bool): Show the object heading even if it has no docstring or children with docstrings. Default: `False`.
132+
show_docstring_attributes (bool): Whether to display the "Attributes" section in the object's docstring. Default: `True`.
133+
show_docstring_description (bool): Whether to display the textual block (including admonitions) in the object's docstring. Default: `True`.
134+
show_docstring_examples (bool): Whether to display the "Examples" section in the object's docstring. Default: `True`.
135+
show_docstring_other_parameters (bool): Whether to display the "Other Parameters" section in the object's docstring. Default: `True`.
136+
show_docstring_parameters (bool): Whether to display the "Parameters" section in the object's docstring. Default: `True`.
137+
show_docstring_raises (bool): Whether to display the "Raises" section in the object's docstring. Default: `True`.
138+
show_docstring_receives (bool): Whether to display the "Receives" section in the object's docstring. Default: `True`.
139+
show_docstring_returns (bool): Whether to display the "Returns" section in the object's docstring. Default: `True`.
140+
show_docstring_warns (bool): Whether to display the "Warns" section in the object's docstring. Default: `True`.
141+
show_docstring_yields (bool): Whether to display the "Yields" section in the object's docstring. Default: `True`.
121142
122143
Attributes: Signatures/annotations options:
123144
annotations_path (str): The verbosity for annotations path: `brief` (recommended), or `source` (as written in the source). Default: `"brief"`.
@@ -168,6 +189,7 @@ def load_inventory(
168189
in_file: BinaryIO,
169190
url: str,
170191
base_url: Optional[str] = None,
192+
domains: list[str] | None = None,
171193
**kwargs: Any,
172194
) -> Iterator[Tuple[str, str]]:
173195
"""Yield items and their URLs from an inventory file streamed from `in_file`.
@@ -178,24 +200,28 @@ def load_inventory(
178200
in_file: The binary file-like object to read the inventory from.
179201
url: The URL that this file is being streamed from (used to guess `base_url`).
180202
base_url: The URL that this inventory's sub-paths are relative to.
203+
domains: A list of domain strings to filter the inventory by, when not passed, "py" will be used.
181204
**kwargs: Ignore additional arguments passed from the config.
182205
183206
Yields:
184207
Tuples of (item identifier, item URL).
185208
"""
209+
domains = domains or ["py"]
186210
if base_url is None:
187211
base_url = posixpath.dirname(url)
188212

189-
for item in Inventory.parse_sphinx(in_file, domain_filter=("py",)).values(): # noqa: WPS526
213+
for item in Inventory.parse_sphinx(in_file, domain_filter=domains).values(): # noqa: WPS526
190214
yield item.name, posixpath.join(base_url, item.uri)
191215

192-
def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102,WPS231
216+
def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem: # noqa: D102,WPS231
193217
module_name = identifier.split(".", 1)[0]
194218
unknown_module = module_name not in self._modules_collection
195219
if config.get("fallback", False) and unknown_module:
196220
raise CollectionError("Not loading additional modules during fallback")
197221

198-
final_config = ChainMap(config, self.default_config)
222+
# See: https://github.com/python/typeshed/issues/8430
223+
mutable_config = dict(copy.deepcopy(config))
224+
final_config = ChainMap(mutable_config, self.default_config)
199225
parser_name = final_config["docstring_style"]
200226
parser_options = final_config["docstring_options"]
201227
parser = parser_name and Parser(parser_name)
@@ -216,7 +242,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102
216242

217243
unresolved, iterations = loader.resolve_aliases(implicit=False, external=False)
218244
if unresolved:
219-
logger.warning(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations")
245+
logger.debug(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations")
220246
logger.debug(f"Unresolved aliases: {', '.join(sorted(unresolved))}")
221247

222248
try:
@@ -232,8 +258,10 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102
232258

233259
return doc_object
234260

235-
def render(self, data: CollectorItem, config: dict) -> str: # noqa: D102 (ignore missing docstring)
236-
final_config = ChainMap(config, self.default_config)
261+
def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa: D102 (ignore missing docstring)
262+
# See https://github.com/python/typeshed/issues/8430
263+
mutabled_config = dict(copy.deepcopy(config))
264+
final_config = ChainMap(mutabled_config, self.default_config)
237265

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

0 commit comments

Comments
 (0)