mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #3673: autodoc: bysource order does not work for a module having __all__
This commit is contained in:
2
CHANGES
2
CHANGES
@@ -100,6 +100,8 @@ Bugs fixed
|
||||
* #7676: autodoc: typo in the default value of autodoc_member_order
|
||||
* #7676: autodoc: wrong value for :member-order: option is ignored silently
|
||||
* #7676: autodoc: member-order="bysource" does not work for C module
|
||||
* #3673: autodoc: member-order="bysource" does not work for a module having
|
||||
__all__
|
||||
* #7668: autodoc: wrong retann value is passed to a handler of
|
||||
autodoc-proccess-signature
|
||||
* #7551: autosummary: a nested class is indexed as non-nested class
|
||||
|
||||
@@ -940,6 +940,25 @@ class ModuleDocumenter(Documenter):
|
||||
)
|
||||
return False, ret
|
||||
|
||||
def sort_members(self, documenters: List[Tuple["Documenter", bool]],
|
||||
order: str) -> List[Tuple["Documenter", bool]]:
|
||||
if order == 'bysource' and self.__all__:
|
||||
# Sort alphabetically first (for members not listed on the __all__)
|
||||
documenters.sort(key=lambda e: e[0].name)
|
||||
|
||||
# Sort by __all__
|
||||
def keyfunc(entry: Tuple[Documenter, bool]) -> int:
|
||||
name = entry[0].name.split('::')[1]
|
||||
if name in self.__all__:
|
||||
return self.__all__.index(name)
|
||||
else:
|
||||
return len(self.__all__)
|
||||
documenters.sort(key=keyfunc)
|
||||
|
||||
return documenters
|
||||
else:
|
||||
return super().sort_members(documenters, order)
|
||||
|
||||
|
||||
class ModuleLevelDocumenter(Documenter):
|
||||
"""
|
||||
|
||||
25
tests/roots/test-ext-autodoc/target/sort_by_all.py
Normal file
25
tests/roots/test-ext-autodoc/target/sort_by_all.py
Normal file
@@ -0,0 +1,25 @@
|
||||
__all__ = ['baz', 'foo', 'Bar']
|
||||
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
|
||||
class Bar:
|
||||
pass
|
||||
|
||||
|
||||
def baz():
|
||||
pass
|
||||
|
||||
|
||||
def qux():
|
||||
pass
|
||||
|
||||
|
||||
class Quux:
|
||||
pass
|
||||
|
||||
|
||||
def foobar():
|
||||
pass
|
||||
@@ -914,6 +914,40 @@ def test_autodoc_member_order(app):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autodoc_module_member_order(app):
|
||||
# case member-order='bysource'
|
||||
options = {"members": 'foo, Bar, baz, qux, Quux, foobar',
|
||||
'member-order': 'bysource',
|
||||
"undoc-members": True}
|
||||
actual = do_autodoc(app, 'module', 'target.sort_by_all', options)
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:module:: target.sort_by_all',
|
||||
'.. py:function:: baz()',
|
||||
'.. py:function:: foo()',
|
||||
'.. py:class:: Bar',
|
||||
'.. py:class:: Quux',
|
||||
'.. py:function:: foobar()',
|
||||
'.. py:function:: qux()',
|
||||
]
|
||||
|
||||
# case member-order='bysource' and ignore-module-all
|
||||
options = {"members": 'foo, Bar, baz, qux, Quux, foobar',
|
||||
'member-order': 'bysource',
|
||||
"undoc-members": True,
|
||||
"ignore-module-all": True}
|
||||
actual = do_autodoc(app, 'module', 'target.sort_by_all', options)
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:module:: target.sort_by_all',
|
||||
'.. py:function:: foo()',
|
||||
'.. py:class:: Bar',
|
||||
'.. py:function:: baz()',
|
||||
'.. py:function:: qux()',
|
||||
'.. py:class:: Quux',
|
||||
'.. py:function:: foobar()',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autodoc_module_scope(app):
|
||||
app.env.temp_data['autodoc:module'] = 'target'
|
||||
|
||||
Reference in New Issue
Block a user