Skip to content

Commit 4a4251c

Browse files
committed
docs: Simplify API docs, fix a few things (stop using future annotations which are not well supported by pytkdocs)
1 parent 2e7ceb2 commit 4a4251c

File tree

9 files changed

+46
-93
lines changed

9 files changed

+46
-93
lines changed

docs/reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
::: mkdocstrings_handlers.python
2+
options:
3+
show_root_full_path: true
4+

docs/usage.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ plugins:
9292
These options affect how the documentation is collected from sources and renderered:
9393
headings, members, docstrings, etc.
9494

95-
::: mkdocstrings_handlers.python.handler.PythonHandler.default_config
95+
### ::: mkdocstrings_handlers.python.handler.PythonHandler.default_config
9696
options:
97+
show_root_heading: false
9798
show_root_toc_entry: false
9899

99100
## Supported docstrings styles
@@ -134,7 +135,7 @@ For example:
134135

135136
```md
136137
::: my_package.my_module
137-
selection:
138+
options:
138139
docstring_style: google # this is the default
139140
docstring_options:
140141
replace_admonitions: no
@@ -153,7 +154,7 @@ For example:
153154

154155
```md
155156
::: my_package.my_module
156-
selection:
157+
options:
157158
docstring_style: google # this is the default
158159
docstring_options:
159160
replace_admonitions: no
@@ -170,7 +171,7 @@ For example:
170171
>
171172
> ```md
172173
> ::: my_package.my_module
173-
> selection:
174+
> options:
174175
> docstring_style: google # this is the default
175176
> docstring_options:
176177
> replace_admonitions: no
@@ -183,7 +184,7 @@ with the `replace_admonitions` option of the Google-style parser:
183184

184185
```yaml
185186
::: my_package.my_module
186-
selection:
187+
options:
187188
docstring_style: google # this is the default
188189
docstring_options:
189190
replace_admonitions: no
@@ -196,10 +197,10 @@ Type annotations are read both in the code and in the docstrings.
196197
> EXAMPLE: **Example with a function**
197198
> **Expand the source at the end to see the original code!**
198199
>
199-
> ::: snippets.function_annotations_google:my_function
200-
> rendering:
201-
> show_root_heading: no
202-
> show_root_toc_entry: no
200+
> ### ::: snippets.function_annotations_google:my_function
201+
> options:
202+
> show_root_heading: false
203+
> show_root_toc_entry: false
203204

204205
### Numpy-style
205206

mkdocs.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ nav:
2020
- Changelog: changelog.md
2121
- Credits: credits.md
2222
- License: license.md
23-
# defer to gen-files + literate-nav
24-
- API reference:
25-
- mkdocstrings-python (legacy): reference/
23+
- API reference: reference.md
2624
- Development:
2725
- Contributing: contributing.md
2826
- Code of Conduct: code_of_conduct.md
@@ -103,9 +101,6 @@ markdown_extensions:
103101
plugins:
104102
- search
105103
- markdown-exec
106-
- gen-files:
107-
scripts:
108-
- scripts/gen_ref_nav.py
109104
- literate-nav:
110105
nav_file: SUMMARY.md
111106
- coverage
@@ -122,16 +117,17 @@ plugins:
122117
ignore_init_summary: true
123118
docstring_section_style: list
124119
filters: ["!^_"]
120+
group_by_category: true
125121
heading_level: 1
126122
inherited_members: true
127123
merge_init_into_class: true
128124
separate_signature: true
125+
show_category_heading: true
129126
show_root_heading: true
130127
show_root_full_path: false
131128
show_signature_annotations: true
132129
show_source: true
133-
show_symbol_type_heading: true
134-
show_symbol_type_toc: true
130+
show_submodules: false
135131
signature_crossrefs: true
136132
summary: true
137133
- git-revision-date-localized:

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ dev-dependencies = [
9595
"markdown-exec>=1.8",
9696
"mkdocs>=1.6",
9797
"mkdocs-coverage>=1.0",
98-
"mkdocs-gen-files>=0.5",
9998
"mkdocs-git-revision-date-localized-plugin>=1.2",
100-
"mkdocs-literate-nav>=0.6",
10199
"mkdocs-material>=9.5",
102100
"mkdocs-minify-plugin>=0.8",
103101
"tomli>=2.0; python_version < '3.11'",

scripts/gen_ref_nav.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/mkdocstrings_handlers/python/debug.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""Debugging utilities."""
22

3-
from __future__ import annotations
4-
53
import os
64
import platform
75
import sys
86
from dataclasses import dataclass
97
from importlib import metadata
8+
from typing import List, Tuple
109

1110

1211
@dataclass
@@ -39,13 +38,13 @@ class Environment:
3938
"""Python interpreter version."""
4039
platform: str
4140
"""Operating System."""
42-
packages: list[Package]
41+
packages: List[Package]
4342
"""Installed packages."""
44-
variables: list[Variable]
43+
variables: List[Variable]
4544
"""Environment variables."""
4645

4746

48-
def _interpreter_name_version() -> tuple[str, str]:
47+
def _interpreter_name_version() -> Tuple[str, str]:
4948
if hasattr(sys, "implementation"):
5049
impl = sys.implementation.version
5150
version = f"{impl.major}.{impl.minor}.{impl.micro}"

src/mkdocstrings_handlers/python/handler.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
It collects data with [`pytkdocs`](https://github.com/pawamoy/pytkdocs).
44
"""
55

6-
from __future__ import annotations
7-
86
import json
97
import os
108
import posixpath
119
import sys
1210
import traceback
1311
from collections import ChainMap
1412
from subprocess import PIPE, Popen
15-
from typing import TYPE_CHECKING, Any, BinaryIO, ClassVar, Iterator, Mapping, MutableMapping
13+
from typing import Any, BinaryIO, ClassVar, Iterator, List, Mapping, MutableMapping, Optional, Tuple
14+
15+
from markdown import Markdown
16+
from mkdocstrings.extension import PluginError
17+
from mkdocstrings.handlers.base import BaseHandler, CollectionError, CollectorItem
18+
from mkdocstrings.inventory import Inventory
19+
from mkdocstrings.loggers import get_logger
1620

1721
from mkdocstrings_handlers.python.rendering import (
1822
do_brief_xref,
@@ -22,14 +26,6 @@
2226
sort_object,
2327
)
2428

25-
from mkdocstrings.extension import PluginError
26-
from mkdocstrings.handlers.base import BaseHandler, CollectionError, CollectorItem
27-
from mkdocstrings.inventory import Inventory
28-
from mkdocstrings.loggers import get_logger
29-
30-
if TYPE_CHECKING:
31-
from markdown import Markdown
32-
3329
# TODO: add a deprecation warning once the new handler handles 95% of use-cases
3430

3531
logger = get_logger(__name__)
@@ -123,9 +119,9 @@ class PythonHandler(BaseHandler):
123119
def __init__(
124120
self,
125121
*args: Any,
126-
setup_commands: list[str] | None = None,
127-
config_file_path: str | None = None,
128-
paths: list[str] | None = None,
122+
setup_commands: Optional[List[str]] = None,
123+
config_file_path: Optional[str] = None,
124+
paths: Optional[List[str]] = None,
129125
**kwargs: Any,
130126
) -> None:
131127
"""Initialize the handler.
@@ -187,8 +183,8 @@ def __init__(
187183
else:
188184
cmd = [sys.executable, "-m", "pytkdocs", "--line-by-line"]
189185

190-
self.process = Popen(
191-
cmd, # noqa: S603
186+
self.process = Popen( # noqa: S603
187+
cmd,
192188
universal_newlines=True,
193189
stdout=PIPE,
194190
stdin=PIPE,
@@ -202,9 +198,9 @@ def load_inventory(
202198
cls,
203199
in_file: BinaryIO,
204200
url: str,
205-
base_url: str | None = None,
201+
base_url: Optional[str] = None,
206202
**kwargs: Any, # noqa: ARG003
207-
) -> Iterator[tuple[str, str]]:
203+
) -> Iterator[Tuple[str, str]]:
208204
"""Yield items and their URLs from an inventory file streamed from `in_file`.
209205
210206
This implements mkdocstrings' `load_inventory` "protocol" (see plugin.py).
@@ -328,7 +324,7 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa
328324
**{"config": final_config, data["category"]: data, "heading_level": heading_level, "root": True},
329325
)
330326

331-
def get_anchors(self, data: CollectorItem) -> tuple[str, ...]: # noqa: D102 (ignore missing docstring)
327+
def get_anchors(self, data: CollectorItem) -> Tuple[str, ...]: # noqa: D102 (ignore missing docstring)
332328
try:
333329
return (data["path"],)
334330
except KeyError:
@@ -344,10 +340,10 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore
344340

345341
def get_handler(
346342
theme: str,
347-
custom_templates: str | None = None,
348-
setup_commands: list[str] | None = None,
349-
config_file_path: str | None = None,
350-
paths: list[str] | None = None,
343+
custom_templates: Optional[str] = None,
344+
setup_commands: Optional[List[str]] = None,
345+
config_file_path: Optional[str] = None,
346+
paths: Optional[List[str]] = None,
351347
**config: Any, # noqa: ARG001
352348
) -> PythonHandler:
353349
"""Simply return an instance of `PythonHandler`.

src/mkdocstrings_handlers/python/rendering.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
"""This module implements rendering utilities."""
22

3-
from __future__ import annotations
4-
53
import sys
6-
from typing import TYPE_CHECKING, Any, Callable
4+
from typing import Any, Callable
75

86
from markupsafe import Markup
9-
7+
from mkdocstrings.handlers.base import CollectorItem
108
from mkdocstrings.loggers import get_logger
119

12-
if TYPE_CHECKING:
13-
from mkdocstrings.handlers.base import CollectorItem
14-
1510
log = get_logger(__name__)
1611

1712

tests/test_collector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Tests for the `collector` module."""
2+
23
from unittest import mock
34

45
import pytest
5-
from mkdocstrings_handlers.python import get_handler
6-
76
from mkdocstrings.handlers.base import CollectionError
87

8+
from mkdocstrings_handlers.python import get_handler
9+
910

1011
@pytest.mark.parametrize(
1112
("retval", "exp_res"),

0 commit comments

Comments
 (0)