Skip to content

Commit 3c32fd4

Browse files
committed
feat: fix toctree in class.rst and avoid nested objects
1 parent bf922ad commit 3c32fd4

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

autoapi/templates/python/class.rst

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,66 @@
3737
{% set visible_classes = obj.classes|rejectattr("inherited")|selectattr("display")|list %}
3838
{% endif %}
3939
{% for klass in visible_classes %}
40-
{{ klass.render()|indent(3) }}
40+
{{ klass.render(own_page_types=[])|indent(3) }}
4141
{% endfor %}
4242
{% if "inherited-members" in autoapi_options %}
4343
{% set visible_properties = obj.properties|selectattr("display")|list %}
4444
{% else %}
4545
{% set visible_properties = obj.properties|rejectattr("inherited")|selectattr("display")|list %}
4646
{% endif %}
47+
{% if "property" in own_page_types and visible_properties %}
48+
Properties
49+
----------
50+
51+
.. toctree::
52+
:hidden:
53+
54+
{% for property in visible_properties %}
55+
{{ property.name }}.rst
56+
{% endfor %}
57+
{% else %}
4758
{% for property in visible_properties %}
4859
{{ property.render()|indent(3) }}
4960
{% endfor %}
61+
{% endif %}
5062
{% if "inherited-members" in autoapi_options %}
5163
{% set visible_attributes = obj.attributes|selectattr("display")|list %}
5264
{% else %}
5365
{% set visible_attributes = obj.attributes|rejectattr("inherited")|selectattr("display")|list %}
5466
{% endif %}
67+
{% if "attribute" in own_page_types and visible_attributes %}
68+
Attributes
69+
----------
70+
71+
.. toctree::
72+
:hidden:
73+
74+
{% for attribute in visible_attributes %}
75+
{{ attribute.name }}.rst
76+
{% endfor %}
77+
{% else %}
5578
{% for attribute in visible_attributes %}
5679
{{ attribute.render()|indent(3) }}
5780
{% endfor %}
81+
{% endif %}
5882
{% if "inherited-members" in autoapi_options %}
5983
{% set visible_methods = obj.methods|selectattr("display")|list %}
6084
{% else %}
6185
{% set visible_methods = obj.methods|rejectattr("inherited")|selectattr("display")|list %}
6286
{% endif %}
87+
{% if "method" in own_page_types and visible_methods %}
88+
Methods
89+
-------
90+
91+
.. toctree::
92+
:hidden:
93+
94+
{% for method in visible_methods %}
95+
{{ method.name }}.rst
96+
{% endfor %}
97+
{% else %}
6398
{% for method in visible_methods %}
6499
{{ method.render()|indent(3) }}
65100
{% endfor %}
101+
{% endif %}
66102
{% endif %}

tests/python/test_pyintegration.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,8 @@ def test_package(self, builder, parse):
12051205

12061206
# TODO: Look for expected contents
12071207

1208-
subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1209-
subpackage_file = parse(subpackage_path)
1208+
# subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1209+
# subpackage_file = parse(subpackage_path)
12101210

12111211
# TODO: Look for expected contents
12121212

@@ -1231,8 +1231,8 @@ def test_module(self, builder, parse):
12311231

12321232
# TODO: Look for expected contents
12331233

1234-
subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1235-
subpackage_file = parse(subpackage_path)
1234+
#subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1235+
#subpackage_file = parse(subpackage_path)
12361236

12371237
# TODO: Look for expected contents
12381238

@@ -1260,8 +1260,8 @@ def test_class(self, builder, parse):
12601260

12611261
# TODO: Look for expected contents
12621262

1263-
subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1264-
subpackage_file = parse(subpackage_path)
1263+
#subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1264+
#subpackage_file = parse(subpackage_path)
12651265

12661266
# TODO: Look for expected contents
12671267

@@ -1270,8 +1270,8 @@ def test_class(self, builder, parse):
12701270

12711271
# TODO: Look for expected contents
12721272

1273-
error_path = "_build/html/autoapi/example/foo/FooError.html"
1274-
error_file = parse(error_path)
1273+
#error_path = "_build/html/autoapi/example/foo/FooError.html"
1274+
#error_file = parse(error_path)
12751275

12761276
# TODO: Look for expected contents
12771277

@@ -1297,8 +1297,8 @@ def test_function(self, builder, parse):
12971297

12981298
# TODO: Look for expected contents
12991299

1300-
subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1301-
subpackage_file = parse(subpackage_path)
1300+
# subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1301+
# subpackage_file = parse(subpackage_path)
13021302

13031303
# TODO: Look for expected contents
13041304

@@ -1307,17 +1307,17 @@ def test_function(self, builder, parse):
13071307

13081308
# TODO: Look for expected contents
13091309

1310-
error_path = "_build/html/autoapi/example/foo/FooError.html"
1311-
error_file = parse(error_path)
1310+
# error_path = "_build/html/autoapi/example/foo/FooError.html"
1311+
# error_file = parse(error_path)
13121312

13131313
# TODO: Look for expected contents
13141314

1315-
foo_path = "_build/html/autoapi/example/foo/Foo.html"
1315+
foo_path = "_build/html/autoapi/example/foo/Foo/index.html"
13161316
foo_file = parse(foo_path)
13171317

13181318
# TODO: Look for expected contents
13191319

1320-
func_path = "_build/html/autoapi/example/foo/module_level_function.html"
1320+
func_path = "_build/html/autoapi/example/module_level_function.html"
13211321
func_file = parse(func_path)
13221322

13231323
# TODO: Look for expected contents
@@ -1338,8 +1338,8 @@ def test_method(self, builder, parse):
13381338

13391339
# TODO: Look for expected contents
13401340

1341-
subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1342-
subpackage_file = parse(subpackage_path)
1341+
# subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1342+
# subpackage_file = parse(subpackage_path)
13431343

13441344
# TODO: Look for expected contents
13451345

@@ -1383,8 +1383,8 @@ def test_attribute(self, builder, parse):
13831383

13841384
# TODO: Look for expected contents
13851385

1386-
subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1387-
subpackage_file = parse(subpackage_path)
1386+
# subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1387+
# subpackage_file = parse(subpackage_path)
13881388

13891389
# TODO: Look for expected contents
13901390

@@ -1438,8 +1438,8 @@ def test_data(self, builder, parse):
14381438

14391439
# TODO: Look for expected contents
14401440

1441-
subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1442-
subpackage_file = parse(subpackage_path)
1441+
# subpackage_path = "_build/html/autoapi/example/subpackage/index.html"
1442+
# subpackage_file = parse(subpackage_path)
14431443

14441444
# TODO: Look for expected contents
14451445

0 commit comments

Comments
 (0)