Skip to content

Commit 47c3745

Browse files
fix: update templates for sphinx-autoapi==3.1.0a4 (#347)
Co-authored-by: Jorge Martinez <[email protected]>
1 parent 25b131f commit 47c3745

File tree

3 files changed

+186
-174
lines changed

3 files changed

+186
-174
lines changed
Lines changed: 159 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
{# ------------------------- Begin macros definition ----------------------- #}
1+
{% if obj.display %}
22

3+
{# ----------------- Start macros definition for tab item ------------------#}
34
{% macro tab_item_from_objects_list(objects_list, title="") -%}
45

5-
.. tab-item:: {{ title }}
6+
.. tab-item:: {{ title }}
67

7-
.. list-table::
8+
.. list-table::
89
:header-rows: 0
910
:widths: auto
1011

@@ -13,145 +14,121 @@
1314
- {{ obj.summary }}
1415
{% endfor %}
1516
{%- endmacro %}
16-
1717
{# --------------------------- End macros definition ----------------------- #}
1818

19-
{% if obj.display %}
20-
21-
{% if own_page_types and obj["type"] in own_page_types %}
22-
{{ obj.short_name }}
23-
{{"=" * obj.name|length }}
24-
{% endif %}
25-
26-
.. py:{{ obj["type"] }}:: {{ obj["short_name"] }}{% if obj["args"] %}({{ obj["args"] }}){% endif %}
27-
28-
{% if own_page_types and obj["type"] in own_page_types %}
29-
:canonical: {{ obj["obj"]["full_name"] }}
30-
{% endif %}
31-
32-
{% for (args, return_annotation) in obj.overloads %}
33-
{{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %}
34-
{% endfor %}
35-
36-
37-
{% if obj.bases %}
38-
{% if "show-inheritance" in autoapi_options %}
39-
Bases: {% for base in obj.bases %}{{ base|link_objs }}{% if not loop.last %}, {% endif %}{% endfor %}
40-
{% endif %}
41-
42-
{% if "show-inheritance-diagram" in autoapi_options and obj.bases != ["object"] %}
43-
.. autoapi-inheritance-diagram:: {{ obj.obj["full_name"] }}
44-
:parts: 1
45-
{% if "private-members" in autoapi_options %}
46-
:private-bases:
47-
{% endif %}
48-
49-
{% endif %}
50-
{% endif %}
51-
52-
{% if obj.docstring -%}
53-
{{ obj.docstring|indent(3) }}
54-
{% endif %}
19+
{% if is_own_page %}
20+
:class:`{{ obj.name }}`
21+
========={{ "=" * obj.name | length }}
5522

56-
{% if "inherited-members" in autoapi_options %}
57-
{% set visible_classes = obj.classes|selectattr("display")|list %}
58-
{% else %}
59-
{% set visible_classes = obj.classes|rejectattr("inherited")|selectattr("display")|list %}
60-
{% endif %}
61-
62-
{% for klass in visible_classes %}
63-
{{ klass.render()|indent(3) }}
64-
{% endfor %}
65-
66-
{% if "inherited-members" in autoapi_options %}
67-
{% set visible_properties = obj.properties|selectattr("display")|list %}
68-
{% else %}
69-
{% set visible_properties = obj.properties|rejectattr("inherited")|selectattr("display")|list %}
70-
{% endif %}
71-
72-
{% if "inherited-members" in autoapi_options %}
73-
{% set visible_attributes = obj.attributes|selectattr("display")|list %}
74-
{% else %}
75-
{% set visible_attributes = obj.attributes|rejectattr("inherited")|selectattr("display")|list %}
76-
{% endif %}
23+
{% endif %}
24+
{% set visible_children = obj.children|selectattr("display")|list %}
25+
{% set own_page_children = visible_children|selectattr("type", "in", own_page_types)|list %}
26+
{% if is_own_page and own_page_children %}
27+
.. toctree::
28+
:hidden:
7729

78-
{% if "inherited-members" in autoapi_options %}
79-
{% set all_visible_methods = obj.methods|selectattr("display")|list %}
80-
{% else %}
81-
{% set all_visible_methods = obj.methods|rejectattr("inherited")|selectattr("display")|list %}
82-
{% endif %}
30+
{% for child in own_page_children %}
31+
{{ child.include_path }}
32+
{% endfor %}
8333

84-
{% set visible_abstract_methods = [] %}
85-
{% set visible_constructor_methods = [] %}
86-
{% set visible_instance_methods = [] %}
87-
{% set visible_special_methods = [] %}
88-
{% set visible_static_methods = [] %}
34+
{% endif %}
35+
.. py:{{ obj.type }}:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}{% if obj.args %}({{ obj.args }}){% endif %}
8936
90-
{% for element in all_visible_methods %}
91-
{% if "abstractmethod" in element.properties %}
92-
{% set _ = visible_abstract_methods.append(element) %}
37+
{% for (args, return_annotation) in obj.overloads %}
38+
{{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %}
9339

94-
{% elif "staticmethod" in element.properties %}
95-
{% set _ = visible_static_methods.append(element) %}
40+
{% endfor %}
41+
{% if obj.bases %}
42+
{% if "show-inheritance" in autoapi_options %}
9643

97-
{% elif "classmethod" in element.properties or element.name in ["__new__", "__init__"] %}
98-
{% set _ = visible_constructor_methods.append(element) %}
44+
Bases: {% for base in obj.bases %}{{ base|link_objs }}{% if not loop.last %}, {% endif %}{% endfor %}
45+
{% endif %}
9946

100-
{% elif element.name.startswith("__") and element.name.endswith("__") and element.name not in ["__new__", "__init__"] %}
101-
{% set _ = visible_special_methods.append(element) %}
10247

103-
{% else %}
104-
{% set _ = visible_instance_methods.append(element) %}
48+
{% if "show-inheritance-diagram" in autoapi_options and obj.bases != ["object"] %}
49+
.. autoapi-inheritance-diagram:: {{ obj.obj["full_name"] }}
50+
:parts: 1
51+
{% if "private-members" in autoapi_options %}
52+
:private-bases:
53+
{% endif %}
10554

55+
{% endif %}
10656
{% endif %}
107-
{% endfor %}
108-
57+
{% if obj.docstring %}
10958

110-
{% set class_objects = visible_properties + visible_attributes + all_visible_methods %}
59+
{{ obj.docstring|indent(3) }}
60+
{% endif %}
61+
{% set this_page_children = visible_children|rejectattr("type", "in", own_page_types)|list %}
62+
{% set visible_abstract_methods = [] %}
63+
{% set visible_constructor_methods = [] %}
64+
{% set visible_instance_methods = [] %}
65+
{% set visible_special_methods = [] %}
66+
{% set visible_static_methods = [] %}
67+
{% set visible_properties = this_page_children|selectattr("type", "equalto", "property")|list %}
68+
{% set visible_attributes = this_page_children|selectattr("type", "equalto", "attribute")|list %}
69+
{% set all_visible_methods = this_page_children|selectattr("type", "equalto", "method")|list %}
70+
{% if all_visible_methods %}
71+
{% for element in all_visible_methods %}
72+
{% if "abstractmethod" in element.properties %}
73+
{% set _ = visible_abstract_methods.append(element) %}
74+
75+
{% elif "staticmethod" in element.properties %}
76+
{% set _ = visible_static_methods.append(element) %}
77+
78+
{% elif "classmethod" in element.properties or element.name in ["__new__", "__init__"] %}
79+
{% set _ = visible_constructor_methods.append(element) %}
80+
81+
{% elif element.name.startswith("__") and element.name.endswith("__") and element.name not in ["__new__", "__init__"] %}
82+
{% set _ = visible_special_methods.append(element) %}
83+
84+
{% else %}
85+
{% set _ = visible_instance_methods.append(element) %}
86+
{% endif %}
87+
{% endfor %}
88+
{% endif %}
11189

112-
{# ------------------------ Begin tabset definition ----------------------- #}
90+
{% if this_page_children %}
11391

114-
{% if class_objects %}
92+
.. py:currentmodule:: {{ obj.short_name }}
93+
{# ------------------------- Begin tab-set definition ----------------------- #}
11594

116-
{% if own_page_types and obj["type"] in own_page_types %}
11795
Overview
11896
--------
119-
.. py:currentmodule:: {{ obj.short_name }}
120-
{% endif %}
97+
12198
.. tab-set::
12299

123-
{% if visible_abstract_methods %}
124-
{{ tab_item_from_objects_list(visible_abstract_methods, "Abstract methods") }}
125-
{% endif %}
100+
{% if visible_abstract_methods %}
101+
{{ tab_item_from_objects_list(visible_abstract_methods, "Abstract methods") }}
102+
{% endif %}
126103

127-
{% if visible_constructor_methods %}
128-
{{ tab_item_from_objects_list(visible_constructor_methods, "Constructors") }}
129-
{% endif %}
104+
{% if visible_constructor_methods %}
105+
{{ tab_item_from_objects_list(visible_constructor_methods, "Constructors") }}
106+
{% endif %}
130107

131-
{% if visible_instance_methods %}
132-
{{ tab_item_from_objects_list(visible_instance_methods, "Methods") }}
133-
{% endif %}
108+
{% if visible_instance_methods %}
109+
{{ tab_item_from_objects_list(visible_instance_methods, "Methods") }}
110+
{% endif %}
134111

135-
{% if visible_properties %}
136-
{{ tab_item_from_objects_list(visible_properties, "Properties") }}
137-
{% endif %}
112+
{% if visible_properties %}
113+
{{ tab_item_from_objects_list(visible_properties, "Properties") }}
114+
{% endif %}
138115

139-
{% if visible_attributes %}
140-
{{ tab_item_from_objects_list(visible_attributes, "Attributes") }}
141-
{% endif %}
116+
{% if visible_attributes %}
117+
{{ tab_item_from_objects_list(visible_attributes, "Attributes") }}
118+
{% endif %}
142119

143-
{% if visible_static_methods %}
144-
{{ tab_item_from_objects_list(visible_static_methods, "Static methods") }}
145-
{% endif %}
120+
{% if visible_static_methods %}
121+
{{ tab_item_from_objects_list(visible_static_methods, "Static methods") }}
122+
{% endif %}
146123

147-
{% if visible_special_methods %}
148-
{{ tab_item_from_objects_list(visible_special_methods, "Special methods") }}
149-
{% endif %}
124+
{% if visible_special_methods %}
125+
{{ tab_item_from_objects_list(visible_special_methods, "Special methods") }}
126+
{% endif %}
150127

151-
{% endif %}
152-
{% endif %}
128+
{% endif %}
153129
{# ---------------------- End class tabset -------------------- #}
154-
{# ---------------------- Begin class datails -------------------- #}
130+
131+
{# ---------------------- Begin class details -------------------- #}
155132

156133
Import detail
157134
-------------
@@ -162,30 +139,85 @@ Import detail
162139
163140
from {{ joined_parts }} import {{ obj["short_name"] }}
164141
165-
{% if visible_properties %}
166-
142+
{% if visible_properties %}
167143
Property detail
168144
---------------
169-
{% for property in visible_properties %}
145+
{% for property in visible_properties %}
170146
{{ property.render() }}
171-
{% endfor %}
172-
{% endif %}
147+
{% endfor %}
148+
{% endif %}
173149

174150

175-
{% if visible_attributes %}
151+
{% if visible_attributes %}
176152
Attribute detail
177153
----------------
178-
{% for attribute in visible_attributes %}
154+
{% for attribute in visible_attributes %}
179155
{{ attribute.render() }}
180-
{% endfor %}
181-
{% endif %}
156+
{% endfor %}
157+
{% endif %}
158+
182159

183-
{% if all_visible_methods %}
160+
{% if all_visible_methods %}
184161
Method detail
185162
-------------
186-
{% for method in all_visible_methods %}
163+
{% for method in all_visible_methods %}
187164
{{ method.render() }}
188-
{% endfor %}
189-
{% endif %}
165+
{% endfor %}
166+
{% endif %}
167+
{% if is_own_page and own_page_children %}
168+
{% set visible_attributes = own_page_children|selectattr("type", "equalto", "attribute")|list %}
169+
{% if visible_attributes %}
170+
Attributes
171+
----------
172+
173+
.. autoapisummary::
174+
175+
{% for attribute in visible_attributes %}
176+
{{ attribute.id }}
177+
{% endfor %}
178+
179+
180+
{% endif %}
181+
{% set visible_exceptions = own_page_children|selectattr("type", "equalto", "exception")|list %}
182+
{% if visible_exceptions %}
183+
Exceptions
184+
----------
185+
186+
.. autoapisummary::
187+
188+
{% for exception in visible_exceptions %}
189+
{{ exception.id }}
190+
{% endfor %}
191+
192+
193+
{% endif %}
194+
{% set visible_classes = own_page_children|selectattr("type", "equalto", "class")|list %}
195+
{% if visible_classes %}
196+
Classes
197+
-------
198+
199+
.. autoapisummary::
200+
201+
{% for klass in visible_classes %}
202+
{{ klass.id }}
203+
{% endfor %}
204+
205+
206+
{% endif %}
207+
{% set visible_methods = own_page_children|selectattr("type", "equalto", "method")|list %}
208+
{% if visible_methods %}
209+
Methods
210+
-------
211+
212+
.. autoapisummary::
213+
214+
{% for method in visible_methods %}
215+
{{ method.id }}
216+
{% endfor %}
217+
218+
219+
{% endif %}
220+
{% endif %}
190221

191222
{# ---------------------- End class details -------------------- #}
223+
{% endif %}

0 commit comments

Comments
 (0)