Skip to content

Commit 0e9bb9b

Browse files
committed
Document package and modules under a "submodules" heading
Closes #450
1 parent 53c2abc commit 0e9bb9b

File tree

3 files changed

+8
-37
lines changed

3 files changed

+8
-37
lines changed

autoapi/templates/python/module.rst

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,10 @@
1212

1313
{% endif %}
1414

15-
{% block subpackages %}
16-
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
17-
{% if visible_subpackages %}
18-
Subpackages
19-
-----------
20-
21-
.. toctree::
22-
:maxdepth: 1
23-
24-
{% for subpackage in visible_subpackages %}
25-
{{ subpackage.include_path }}
26-
{% endfor %}
27-
28-
29-
{% endif %}
30-
{% endblock %}
3115
{% block submodules %}
16+
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
3217
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
18+
{% set visible_submodules = (visible_subpackages + visible_submodules)|sort %}
3319
{% if visible_submodules %}
3420
Submodules
3521
----------

docs/changes/450.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document packages and modules under a single "submodules" heading

tests/python/test_own_page_option.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ def test_package(self, parse):
2828
assert docstring.text == "This is a docstring."
2929

3030
# There should be links to the children with their own page
31-
subpackages = package_file.find(id="subpackages")
32-
assert subpackages
33-
assert subpackages.find("a", string="package.subpackage")
3431
submodules = package_file.find(id="submodules")
3532
assert submodules
33+
assert submodules.find("a", string="package.subpackage")
3634
assert submodules.find("a", string="package.submodule")
3735

3836
# There should not be links to the children without their own page
@@ -66,7 +64,6 @@ def test_subpackage(self, parse):
6664
assert docstring.text == "This is a docstring."
6765

6866
# There should be links to the children with their own page
69-
assert not subpackage_file.find(id="subpackages")
7067
submodules = subpackage_file.find(id="submodules")
7168
assert submodules
7269
assert submodules.find("a", string="package.subpackage.submodule")
@@ -98,7 +95,6 @@ def test_module(self, parse):
9895

9996
# There should not be links to the children without their own page
10097
assert not submodule_file.find(id="submodules")
101-
assert not submodule_file.find(id="subpackages")
10298
assert not submodule_file.find(id="attributes")
10399
assert not submodule_file.find(id="exceptions")
104100
assert not submodule_file.find(id="classes")
@@ -177,11 +173,9 @@ def test_package(self, parse):
177173
assert docstring.text == "This is a docstring."
178174

179175
# There should be links to the children with their own page
180-
subpackages = package_file.find(id="subpackages")
181-
assert subpackages
182-
assert subpackages.find("a", string="package.subpackage")
183176
submodules = package_file.find(id="submodules")
184177
assert submodules
178+
assert submodules.find("a", string="package.subpackage")
185179
assert submodules.find("a", string="package.submodule")
186180
exceptions = package_file.find(id="exceptions")
187181
assert exceptions
@@ -230,7 +224,6 @@ def test_module(self, parse):
230224

231225
# There should not be links to the children without their own page
232226
assert not submodule_file.find(id="submodules")
233-
assert not submodule_file.find(id="subpackages")
234227
assert not submodule_file.find(id="attributes")
235228
assert not submodule_file.find(id="functions")
236229

@@ -388,11 +381,9 @@ def test_package(self, parse):
388381
assert docstring.text == "This is a docstring."
389382

390383
# There should be links to the children with their own page
391-
subpackages = package_file.find(id="subpackages")
392-
assert subpackages
393-
assert subpackages.find("a", string="package.subpackage")
394384
submodules = package_file.find(id="submodules")
395385
assert submodules
386+
assert submodules.find("a", string="package.subpackage")
396387
assert submodules.find("a", string="package.submodule")
397388
classes = package_file.find(id="classes")
398389
assert classes
@@ -445,7 +436,6 @@ def test_module(self, parse):
445436

446437
# There should not be links to the children without their own page
447438
assert not submodule_file.find(id="submodules")
448-
assert not submodule_file.find(id="subpackages")
449439
assert not submodule_file.find(id="attributes")
450440

451441
# Children without their own page should be rendered on this page,
@@ -578,11 +568,9 @@ def test_package(self, parse):
578568
assert docstring.text == "This is a docstring."
579569

580570
# There should be links to the children with their own page
581-
subpackages = package_file.find(id="subpackages")
582-
assert subpackages
583-
assert subpackages.find("a", string="package.subpackage")
584571
submodules = package_file.find(id="submodules")
585572
assert submodules
573+
assert submodules.find("a", string="package.subpackage")
586574
assert submodules.find("a", string="package.submodule")
587575
classes = package_file.find(id="classes")
588576
assert classes
@@ -635,7 +623,6 @@ def test_module(self, parse):
635623

636624
# There should not be links to the children without their own page
637625
assert not submodule_file.find(id="submodules")
638-
assert not submodule_file.find(id="subpackages")
639626
assert not submodule_file.find(id="attributes")
640627

641628
# Children without their own page should be rendered on this page,
@@ -792,11 +779,9 @@ def test_package(self, parse):
792779
assert docstring.text == "This is a docstring."
793780

794781
# There should be links to the children with their own page
795-
subpackages = package_file.find(id="subpackages")
796-
assert subpackages
797-
assert subpackages.find("a", string="package.subpackage")
798782
submodules = package_file.find(id="submodules")
799783
assert submodules
784+
assert submodules.find("a", string="package.subpackage")
800785
assert submodules.find("a", string="package.submodule")
801786
classes = package_file.find(id="classes")
802787
assert classes
@@ -843,7 +828,6 @@ def test_module(self, parse):
843828

844829
# There should not be links to the children without their own page
845830
assert not submodule_file.find(id="submodules")
846-
assert not submodule_file.find(id="subpackages")
847831

848832
# Children without their own page should be rendered on this page,
849833
# and children with their own page should not be rendered on this page.

0 commit comments

Comments
 (0)