Skip to content

Commit fc59f3b

Browse files
authored
📚 DOCS: Use sphinx-autodoc2 for API (#704)
This will allow moving source docstrings to use MyST instead of rST 🎉
1 parent cce4684 commit fc59f3b

14 files changed

Lines changed: 48 additions & 132 deletions

File tree

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ coverage:
66
threshold: 0.5%
77
patch:
88
default:
9-
target: 75%
9+
target: 60%
1010
threshold: 0.5%

docs/api/reference.rst

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

docs/conf.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
# ones.
2929
extensions = [
3030
"myst_parser",
31-
"sphinx.ext.autodoc",
31+
"autodoc2",
3232
"sphinx.ext.intersphinx",
3333
"sphinx.ext.viewcode",
34+
"sphinx.ext.autodoc",
3435
"sphinx_design",
3536
"sphinxext.rediraffe",
3637
"sphinxcontrib.mermaid",
@@ -57,30 +58,27 @@
5758

5859
# -- Autodoc settings ---------------------------------------------------
5960

60-
autodoc_member_order = "bysource"
61+
autodoc2_packages = ["../myst_parser"]
62+
autodoc2_hidden_objects = ["dunder", "private", "inherited"]
63+
autodoc2_replace_annotations = [
64+
("re.Pattern", "typing.Pattern"),
65+
("markdown_it.MarkdownIt", "markdown_it.main.MarkdownIt"),
66+
]
67+
autodoc2_replace_bases = [
68+
("myst_parser._compat.Protocol", "typing.Protocol"),
69+
("myst_parser._compat.TypedDict", "typing.TypedDict"),
70+
("sphinx.directives.SphinxDirective", "sphinx.util.docutils.SphinxDirective"),
71+
]
6172
nitpicky = True
73+
nitpick_ignore_regex = [
74+
(r"py:.*", r"docutils\..*"),
75+
]
6276
nitpick_ignore = [
63-
("py:class", "docutils.nodes.document"),
64-
("py:class", "docutils.nodes.docinfo"),
65-
("py:class", "docutils.nodes.Element"),
66-
("py:class", "docutils.nodes.Node"),
67-
("py:class", "docutils.nodes.field_list"),
68-
("py:class", "docutils.nodes.problematic"),
69-
("py:class", "docutils.nodes.pending"),
70-
("py:class", "docutils.nodes.system_message"),
71-
("py:class", "docutils.statemachine.StringList"),
72-
("py:class", "docutils.parsers.rst.directives.misc.Include"),
73-
("py:class", "docutils.parsers.rst.Parser"),
74-
("py:class", "docutils.utils.Reporter"),
75-
("py:class", "nodes.Element"),
76-
("py:class", "nodes.Node"),
77-
("py:class", "nodes.system_message"),
78-
("py:class", "Directive"),
79-
("py:class", "Include"),
80-
("py:class", "StringList"),
81-
("py:class", "DocutilsRenderer"),
82-
("py:class", "MockStateMachine"),
77+
("py:obj", "myst_parser._docs._ConfigBase"),
8378
("py:exc", "MarkupError"),
79+
("py:class", "sphinx.util.typing.Inventory"),
80+
("py:class", "sphinx.writers.html.HTMLTranslator"),
81+
("py:obj", "sphinx.transforms.post_transforms.ReferencesResolver"),
8482
]
8583

8684
# -- MyST settings ---------------------------------------------------
@@ -166,6 +164,7 @@
166164
"sphinx/intro.md": "intro.md",
167165
"using/use_api.md": "api/index.md",
168166
"api/index.md": "api/reference.rst",
167+
"api/reference.rst": "apidocs/index.md",
169168
"using/syntax.md": "syntax/syntax.md",
170169
"using/syntax-optional.md": "syntax/optional.md",
171170
"using/reference.md": "syntax/reference.md",

docs/docutils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ stylesheet-dirs: path/to/html5_polyglot/
5959
stylesheet-path: minimal.css, responsive.css
6060
```
6161

62-
You can also use the {py:class}`myst_parser.docutils_.Parser` class programmatically with the [Docutils publisher API](https://docutils.sourceforge.io/docs/api/publisher.html):
62+
You can also use the {py:class}`myst_parser.parsers.docutils_.Parser` class programmatically with the [Docutils publisher API](https://docutils.sourceforge.io/docs/api/publisher.html):
6363

6464
```python
6565
from docutils.core import publish_string

docs/faq/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ However, the special [`eval-rst` directive](syntax/directives/parsing) can be us
118118
.. autoclass:: myst_parser.mocking.MockRSTParser
119119
:show-inheritance:
120120
:members: parse
121+
:noindex:
121122
```
122123

123124
As with other objects in MyST, this can then be referenced:

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ develop/index.md
148148
develop/_changelog.md
149149
syntax/reference
150150
develop/background.md
151-
api/reference.rst
151+
apidocs/index.rst
152152
```
153153

154154
[commonmark]: https://commonmark.org/

myst_parser/config/dc_validators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ def __call__(
4343
...
4444

4545

46-
def instance_of(type: type[Any] | tuple[type[Any], ...]) -> ValidatorType:
46+
def instance_of(type_: type[Any] | tuple[type[Any], ...]) -> ValidatorType:
4747
"""
4848
A validator that raises a `TypeError` if the initializer is called
4949
with a wrong type for this particular attribute (checks are performed using
5050
`isinstance` therefore it's also valid to pass a tuple of types).
5151
52-
:param type: The type to check for.
52+
:param type_: The type to check for.
5353
"""
5454

5555
def _validator(inst, field, value, suffix=""):
5656
"""
5757
We use a callable class to be able to change the ``__repr__``.
5858
"""
59-
if not isinstance(value, type):
59+
if not isinstance(value, type_):
6060
raise TypeError(
61-
f"'{field.name}{suffix}' must be of type {type!r} "
61+
f"'{field.name}{suffix}' must be of type {type_!r} "
6262
f"(got {value!r} that is a {value.__class__!r})."
6363
)
6464

myst_parser/docutils_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""A module for compatibility with the docutils>=0.17 `include` directive, in RST documents::
1+
"""A module for compatibility with the docutils>=0.17 `include` directive, in RST documents:
2+
3+
For example::
24
35
.. include:: path/to/file.md
46
:parser: myst_parser.docutils_

myst_parser/inventory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class InventoryType(TypedDict):
4343
version: str
4444
"""The version of the project."""
4545
base_url: str | None
46-
"""The base URL of the `loc`s."""
46+
"""The base URL of the `loc`."""
4747
objects: dict[str, dict[str, dict[str, InventoryItemType]]]
4848
"""Mapping of domain -> object type -> name -> item."""
4949

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
"""Conversion of Markdown-it tokens to docutils AST."""
1+
"""Conversion of Markdown-it tokens to docutils AST.
2+
3+
These renderers take the markdown-it parsed token stream
4+
and convert it to the docutils AST.
5+
The sphinx renderer is a subclass of the docutils one,
6+
with some additional methods only available
7+
*via* sphinx e.g. multi-document cross-referencing.
8+
"""

0 commit comments

Comments
 (0)