Skip to content

Commit 91b63e0

Browse files
committed
Allows passing True as autodocsumm_section_sorter for simple sorting
1 parent 3693a60 commit 91b63e0

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

autodocsumm/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ def get_grouped_documenters(self, all_members=False):
271271
documenters.setdefault(section, []).append(e)
272272
self.options.update(options_save)
273273

274-
if callable(self.env.config.autodocsumm_section_sorter):
275-
return {k: documenters[k] for k in sorted(documenters, key=self.env.config.autodocsumm_section_sorter)}
274+
sort_option = self.env.config.autodocsumm_section_sorter
275+
if sort_option is True:
276+
return {k: documenters[k] for k in sorted(documenters)}
277+
elif callable(sort_option):
278+
return {k: documenters[k] for k in sorted(documenters, key=sort_option)}
276279
else:
277280
return documenters
278281

docs/conf_settings.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ Configuration values and events
139139

140140
.. confval:: autodocsumm_section_sorter
141141

142-
This can be set with a callable that is passed to :func:`sorted` as key
143-
argument to sort the the summary sections by their name. Example usage for
144-
an alphanumerical order::
145-
146-
autodocsumm_section_sorter = lambda s: s
142+
When ``True`` the summarizing sections will be sorted alphanumerically by
143+
their section title. Alternatively a callable can be set that is passed to
144+
:func:`sorted` as key argument to sort the the summary sections by their
145+
name.
146+
The default value is ``None``.
147+
Example usage with a tuple that defines an arbitrary order:
148+
149+
sections_order = ("Public methods", "Attributes", "Private methods")
150+
autodocsumm_section_sorter = lambda title: sections_order.index(title)

tests/test-root/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
autodata_content = 'both'
2525

26-
autodocsumm_section_sorter = lambda a: a
26+
autodocsumm_section_sorter = True
2727

2828

2929
def member_filter(app, what, name, obj, skip, options):

0 commit comments

Comments
 (0)