在sphinx autodoc中对成员进行不区分大小写的排序



从sphinx.ext.autodoc文档中,autodoc_member_order可以是alphabeticalgroupwisebysource。可以按字母顺序不区分大小写排序吗?我想在"RGB"之前对"比率"进行排序。

据我所知,斯芬克斯没有内置的选项。

物体检查的结果在此功能中排序:

def safe_getmembers(object, predicate=None, attr_getter=safe_getattr):
# type: (Any, Callable[[unicode], bool], Callable) -> List[Tuple[unicode, Any]]
"""A version of inspect.getmembers() that uses safe_getattr()."""
results = []  # type: List[Tuple[unicode, Any]]
for key in dir(object):
try:
value = attr_getter(object, key, None)
except AttributeError:
continue
if not predicate or predicate(value):
results.append((key, value))
results.sort()
return results

您可以尝试通过以下操作来覆盖该函数:

from sphinx.util import inspect
def custom_safe_getmembers(object, predicate=None, attr_getter=safe_getattr):
# type: (Any, Callable[[unicode], bool], Callable) -> List[Tuple[unicode, Any]]
"""A version of inspect.getmembers() that uses safe_getattr()."""
results = []  # type: List[Tuple[unicode, Any]]
for key in dir(object):
try:
value = attr_getter(object, key, None)
except AttributeError:
continue
if not predicate or predicate(value):
results.append((key, value))
results.sort(lambda (k, v): (k.lower(), v))
return results
inspect.safe_getmembers = custom_safe_getmembers

我还没有机会尝试这个,所以要小心!

相关内容

  • 没有找到相关文章

最新更新