本文整理汇总了Python中sphinx.ext.autosummary.Autosummary方法的典型用法代码示例。如果您正苦于以下问题:Python autosummary.Autosummary方法的具体用法?Python autosummary.Autosummary怎么用?Python autosummary.Autosummary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.ext.autosummary
的用法示例。
在下文中一共展示了autosummary.Autosummary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import Autosummary [as 别名]
def setup(app):
app.connect('autodoc-skip-member', skip_deprecated)
try:
from sphinx.ext.autosummary import Autosummary
from sphinx.ext.autosummary import get_documenter
from docutils.parsers.rst import directives
from sphinx.util.inspect import safe_getattr
class AutoAutoSummary(Autosummary):
option_spec = {
'methods': directives.unchanged,
'attributes': directives.unchanged
}
required_arguments = 1
@staticmethod
def get_members(obj, typ, include_public=None):
if not include_public:
include_public = []
items = []
for name in dir(obj):
try:
documenter = get_documenter(safe_getattr(obj, name),
obj)
except AttributeError:
continue
if documenter.objtype == typ:
items.append(name)
public = [x for x in items
if x in include_public or not x.startswith('_')]
return public, items
def run(self):
clazz = str(self.arguments[0])
try:
(module_name, class_name) = clazz.rsplit('.', 1)
m = __import__(module_name, globals(), locals(),
[class_name])
c = getattr(m, class_name)
if 'methods' in self.options:
_, methods = self.get_members(c,
'method', ['__init__'])
self.content = ["~%s.%s" % (clazz, method)
for method in methods
if not method.startswith('_')]
if 'attributes' in self.options:
_, attribs = self.get_members(c, 'attribute')
self.content = ["~%s.%s" % (clazz, attrib)
for attrib in attribs
if not attrib.startswith('_')]
finally:
return super(AutoAutoSummary, self).run()
app.add_directive('autoautosummary', AutoAutoSummary)
except BaseException as e:
raise e