Skip to content

Commit e50fc2c

Browse files
authored
Add API doc using autosummary. (#23)
Document API by generating docs with autosummary for each module. * README.md * ROADMAP.md * docs/sphinx/_static/css/api-docs.css * docs/sphinx/_templates/custom-module-template.rst * docs/sphinx/api/sphinx_polyversion.rst * docs/sphinx/conf.py * docs/sphinx/index.rst * sphinx_polyversion/git.py : Fix docs. * sphinx_polyversion/json.py : Fix docs.
1 parent affbb42 commit e50fc2c

File tree

9 files changed

+109
-8
lines changed

9 files changed

+109
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ that isn't merged in the end.
233233

234234
By contributing you affirm the [Developer Certificate of Origin](https://developercertificate.org/) and license your work under the terms of this repository.
235235

236+
New top-level modules must be added to `docs/sphinx/api/sphinx_polyversion.rst`.
237+
236238
## License
237239

238240
MIT License <br>

ROADMAP.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@
7272
- [ ] Updating docs from old versions using cherry-pick
7373
- [ ] Subclassing guide
7474
- [ ] Reference
75+
- [ ] Further explanation accompanying the reference (for new contributors) and users who want to extend inside `poly.py`
7576
- [ ] Command line syntax
76-
- [ ] API
77-
- [ ] Abstract classes
78-
- [ ] Implementations
77+
- [x] API
78+
- [x] Abstract classes
79+
- [x] Implementations
7980
- [ ] Contributing Standards
8081
- [ ] Contributing
8182
- [ ] Workflows, Policies

docs/sphinx/_static/css/api-docs.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* align tables left in API docs (default was center) */
2+
table.autosummary.longtable {
3+
margin-left: 0;
4+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. automodule:: {{ fullname }}
4+
5+
{% block attributes %}
6+
{% if attributes %}
7+
.. rubric:: Module Attributes
8+
9+
.. autosummary::
10+
{% for item in attributes %}
11+
{{ item }}
12+
{%- endfor %}
13+
{% endif %}
14+
{% endblock %}
15+
16+
{% block functions %}
17+
{% if functions %}
18+
.. rubric:: {{ _('Functions') }}
19+
20+
.. autosummary::
21+
{% for item in functions %}
22+
{{ item }}
23+
{%- endfor %}
24+
{% endif %}
25+
{% endblock %}
26+
27+
{% block classes %}
28+
{% if classes %}
29+
.. rubric:: {{ _('Classes') }}
30+
31+
.. autosummary::
32+
{% for item in classes %}
33+
{{ item }}
34+
{%- endfor %}
35+
{% endif %}
36+
{% endblock %}
37+
38+
{% block exceptions %}
39+
{% if exceptions %}
40+
.. rubric:: {{ _('Exceptions') }}
41+
42+
.. autosummary::
43+
{% for item in exceptions %}
44+
{{ item }}
45+
{%- endfor %}
46+
{% endif %}
47+
{% endblock %}
48+
49+
{% block modules %}
50+
{% if modules %}
51+
.. rubric:: Modules
52+
53+
.. autosummary::
54+
:toctree:
55+
:template: custom-module-template.rst
56+
:recursive:
57+
{% for item in modules %}
58+
{{ item }}
59+
{%- endfor %}
60+
61+
{% endif %}
62+
{% endblock %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. currentmodule:: sphinx_polyversion
2+
3+
Public API
4+
==========
5+
6+
.. autosummary::
7+
:toctree: .
8+
:template: custom-module-template.rst
9+
:recursive:
10+
11+
api
12+
builder
13+
driver
14+
environment
15+
git
16+
json
17+
log
18+
main
19+
pyvenv
20+
sphinx
21+
utils
22+
vcs

docs/sphinx/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
"sphinx.ext.githubpages",
5757
]
5858

59+
autosummary_ignore_module_all = False
60+
autodoc_default_options = {
61+
"members": True,
62+
"show-inheritance": True,
63+
"special-members": "__call__, __aenter__, __aexit__",
64+
}
65+
5966
exclude_patterns = []
6067

6168
myst_enable_extensions = [
@@ -92,6 +99,7 @@
9299
#
93100
# style the version selector
94101
"css/version-selector.css",
102+
"css/api-docs.css",
95103
]
96104

97105
templates_path = [

docs/sphinx/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Table of Contents
2424
:maxdepth: 2
2525
:caption: Reference
2626

27+
api/sphinx_polyversion
28+
2729
.. toctree::
2830
:maxdepth: 1
2931
:caption: Development

sphinx_polyversion/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ async def predicate(self, root: Path, ref: GitRef) -> bool:
485485
"""
486486
Check whether a revision should be build.
487487
488-
This predicate is used by :method:`retrieve` to filter the
488+
This predicate is used by :meth:`retrieve` to filter the
489489
git references retrieved.
490490
491491
Parameters

sphinx_polyversion/json.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _from_json_fields(cls: Type[T], o: Any) -> T:
7474
----------
7575
o : Any
7676
The deserialized fields as they were returned
77-
by :method:`_json_fields` earlier.
77+
by :meth:`_json_fields` earlier.
7878
7979
Returns
8080
-------
@@ -262,7 +262,7 @@ def __call__(self, o: JSONable) -> JSON_TYPE_DUMP:
262262
263263
Notes
264264
-----
265-
Calls :method:`transform` internally.
265+
Calls :meth:`transform` internally.
266266
267267
"""
268268
return self.transform(o)
@@ -285,7 +285,7 @@ class Decoder(json.JSONDecoder):
285285
protocol or a :class:`JSONHook` has to be implemented for the type.
286286
2. The object has to be encoded in the correct format as done by :class:`Encoder`.
287287
3. THe hook or class has to be registered with this decoder. You can use
288-
:method:`register` for that. This method can also be used as a class decorator.
288+
:meth:`register` for that. This method can also be used as a class decorator.
289289
290290
Parameters
291291
----------
@@ -505,7 +505,7 @@ def from_json(cls: str, o: JSON_TYPE) -> Any: # noqa: PLW0211
505505
Instanciate an object from its fields.
506506
507507
This method is only called with supported instances that were
508-
encoded with the help of :method:`fields`.
508+
encoded with the help of :meth:`fields`.
509509
510510
Parameters
511511
----------

0 commit comments

Comments
 (0)