With Sphinx for Python how is it possible to avoid having all the method/function names sorted alphabetically in HTML? I want to keep them in the very same order as they are found in the source code.
Asked
Active
Viewed 9,162 times
2 Answers
61
From the sphinx.ext.autodoc documentation:
autodoc_member_order
This value selects if automatically documented members are sorted alphabetical (value 'alphabetical'), by member type (value 'groupwise') or by source order (value 'bysource'). The default is alphabetical.
Note that for source order, the module must be a Python module with the source code available.
So somewhere in your conf.py file, put:
autodoc_member_order = 'bysource'

Community
- 1
- 1

James Scholes
- 7,686
- 3
- 19
- 20
-
If Sphinx can't find your source code, make sure you have the path included in `conf.py` via `sys.path.insert(0, os.path.abspath('path/to/source')`. In my case, this path was wrong but Sphinx didn't give an error because the module was also locally installed and could be imported without issue, even though Sphinx couldn't find the source code. – eatcrayons Jul 19 '17 at 23:33
-
For modules without .py source code (e.g. C-extensions or cython), the module's `__all__` attribute is used to define the ordering. – Demi-Lune Mar 05 '20 at 18:27
14
For a single .rst
file (watch the last string):
foo.bar module
=========================
.. automodule:: foo.bar
:members:
:undoc-members:
:show-inheritance:
:member-order: bysource

banderlog013
- 2,207
- 24
- 33