Skip to content

Commit 327cd08

Browse files
authored
Merge pull request #38 from Chilipp/class_order
allow specifying the member-order
2 parents bf88329 + 7b619e4 commit 327cd08

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

autodocsumm/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ def get_grouped_documenters(self, all_members=False):
199199
documenter = classes[-1](self.directive, full_mname, self.indent)
200200
memberdocumenters.append((documenter,
201201
members_check_module and not isattr))
202+
203+
member_order = (
204+
self.options.member_order or self.env.config.autodoc_member_order
205+
)
206+
try:
207+
memberdocumenters = self.sort_members(
208+
memberdocumenters, member_order
209+
)
210+
except AttributeError: # sphinx<3.0
211+
pass
212+
202213
documenters = OrderedDict()
203214
for e in memberdocumenters:
204215
section = self.member_sections.get(

tests/sphinx_supp/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Example documentation
66
test_module
77
test_module_summary_only
88
test_class
9+
test_class_order
910
test_class_summary_only
1011
test_inherited
1112
test_module_title
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dummy Class Doc
2+
===============
3+
4+
.. autoclass:: dummy.TestClass
5+
:member-order: bysource

tests/test_autodocsumm.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,30 @@ def test_class(self, app, status, warning):
160160
html, '<span class="pre">InnerClass</span>', 'Classes',
161161
'DummySection'))
162162

163+
@with_app(buildername='html', srcdir=sphinx_supp,
164+
copy_srcdir_to_tmpdir=True)
165+
@unittest.skipIf(
166+
sphinx_version[:2] < [3, 1], "Only available for sphinx>=3"
167+
)
168+
def test_class_order(self, app, status, warning):
169+
app.build()
170+
html = get_html(app, '/test_class_order.html')
171+
172+
if sphinx_version[:2] > [3, 1]:
173+
self.assertIn(
174+
'<span class="pre">instance_attribute</span>',
175+
html)
176+
elif sphinx_version[:2] < [3, 1]:
177+
self.assertIn(
178+
'<span class="pre">dummy.TestClass.instance_attribute</span>',
179+
html)
180+
181+
self.assertIn('<span class="pre">test_attr</span>', html)
182+
self.assertIn('<span class="pre">large_data</span>', html)
183+
184+
self.assertLess(html.index('<span class="pre">test_attr</span>'),
185+
html.index('<span class="pre">large_data</span>'))
186+
163187
@with_app(buildername='html', srcdir=sphinx_supp,
164188
copy_srcdir_to_tmpdir=True)
165189
def test_class_summary_only(self, app, status, warning):

0 commit comments

Comments
 (0)