Skip to content

Commit 3277492

Browse files
committed
Expand autosummary templates, config
1 parent 3350193 commit 3277492

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

doc/_template/autosummary/class.rst

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. From https://stackoverflow.com/a/62613202/2362198
2+
3+
{{ fullname | escape | underline}}
4+
5+
.. currentmodule:: {{ module }}
6+
7+
.. autoclass:: {{ objname }}
8+
:members:
9+
:show-inheritance:
10+
:inherited-members:
11+
12+
{% block methods %}
13+
.. automethod:: __init__
14+
15+
{% if methods %}
16+
.. rubric:: {{ _('Methods') }}
17+
18+
.. autosummary::
19+
{% for item in methods %}
20+
~{{ name}}.{{ item }}
21+
{%- endfor %}
22+
{% endif %}
23+
{% endblock %}
24+
25+
{% block attributes %}
26+
{% if attributes %}
27+
.. rubric:: {{ _('Attributes') }}
28+
29+
.. autosummary::
30+
{% for item in attributes %}
31+
~{{ name}}.{{ item }}
32+
{%- endfor %}
33+
{% endif %}
34+
{% endblock %}

doc/_template/autosummary/module.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. From https://stackoverflow.com/a/62613202/2362198
22
3-
.. {{ (":mod:`." + fullname.split(".", maxsplit=1)[1] + "` " + objtype) | underline(line="*") }}
3+
.. {{ (":mod:`." + fullname.split(".", maxsplit=1)[1] + "` " + objtype) }}
44
55
Code reference
66
==============
@@ -59,13 +59,11 @@ Code reference
5959
.. rubric:: {{ _('Classes') }}
6060

6161
.. autosummary::
62+
:toctree:
63+
:template: autosummary/class.rst
6264
{% for item in classes %}
6365
{{ item }}
6466
{%- endfor %}
65-
66-
{% for item in classes %}
67-
.. autoclass:: {{ item }}
68-
{%- endfor %}
6967
{% endif %}
7068
{% endblock %}
7169

doc/conf.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from pathlib import Path
88
from typing import TYPE_CHECKING
99

10+
import transport_data # noqa: F401
11+
1012
if TYPE_CHECKING:
1113
import sphinx.application
1214

@@ -54,6 +56,10 @@ def setup(app: "sphinx.application.Sphinx"):
5456

5557
html_css_files = ["css/custom.css"]
5658

59+
# -- Options for sphinx.ext.autosummary ------------------------------------------------
60+
61+
autosummary_generate = True
62+
5763
# -- Options for sphinx.ext.extlinks ---------------------------------------------------
5864

5965
extlinks = {
@@ -67,6 +73,7 @@ def setup(app: "sphinx.application.Sphinx"):
6773
intersphinx_mapping = {
6874
"click": ("https://click.palletsprojects.com/en/8.1.x/", None),
6975
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
76+
"platformdirs": ("https://platformdirs.readthedocs.io/en/latest/", None),
7077
"pooch": ("https://www.fatiando.org/pooch/latest/", None),
7178
"py": ("https://docs.python.org/3/", None),
7279
"pytest": ("https://docs.pytest.org/en/stable/", None),
@@ -93,7 +100,10 @@ def linkcode_resolve(domain, info):
93100
rel = Path(module.__file__).relative_to(base_path[info["module"].split(".")[0]])
94101

95102
# The object itself
96-
obj = getattr(module, info["fullname"])
103+
try:
104+
obj = getattr(module, info["fullname"])
105+
except AttributeError:
106+
return None
97107
try:
98108
# First line number
99109
firstlineno = obj.__code__.co_firstlineno
@@ -103,3 +113,8 @@ def linkcode_resolve(domain, info):
103113
fragment = f"#L{firstlineno}" # Function, class, or other definition
104114

105115
return f"{base_url}{rel}{fragment}"
116+
117+
118+
# -- Options for sphinx.ext.napoleon ---------------------------------------------------
119+
120+
napoleon_preprocess_types = True

0 commit comments

Comments
 (0)