本文整理汇总了Python中sphinx.ext.autosummary.get_documenter方法的典型用法代码示例。如果您正苦于以下问题:Python autosummary.get_documenter方法的具体用法?Python autosummary.get_documenter怎么用?Python autosummary.get_documenter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.ext.autosummary
的用法示例。
在下文中一共展示了autosummary.get_documenter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_members
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
def _get_members(self, class_obj, member_type, include_in_public=None):
"""
Return class members of the specified type.
class_obj: Class object.
member_type: Member type ('method' or 'attribute').
include_in_public: set/list/tuple with member names that should be
included in public members in addition to the public names (those
starting without underscore).
Returns:
tuple(public_members, all_members): Names of the class members of
the specified member type (public / all).
"""
try:
app = self.state.document.settings.env.app
except AttributeError:
app = None
if not include_in_public:
include_in_public = []
all_members = []
for member_name in dir(class_obj):
try:
documenter = get_documenter(
app,
safe_getattr(class_obj, member_name),
class_obj)
except AttributeError:
continue
if documenter.objtype == member_type:
all_members.append(member_name)
public_members = [x for x in all_members
if x in include_in_public or not x.startswith('_')]
return public_members, all_members
示例2: get_members
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
def get_members(doc, obj, typ, include_public=None, signal=False, enum=False):
try:
if not include_public:
include_public = []
items = []
for name in dir(obj):
if name not in obj.__dict__.keys():
continue
try:
chobj = safe_getattr(obj, name)
documenter = get_documenter(doc.settings.env.app, chobj, obj)
#cl = get_class_that_defined_method(chobj)
#print(name, chobj.__qualname__, type(chobj), issubclass(chobj, Enum), documenter.objtype)
if documenter.objtype == typ:
if typ == 'attribute':
if signal and type(chobj) != PyQt5.QtCore.pyqtSignal:
continue
if not signal and type(chobj) == PyQt5.QtCore.pyqtSignal:
continue
elif typ == 'class':
if enum and not issubclass(chobj, Enum):
continue
if not enum and issubclass(chobj, Enum):
continue
items.append(name)
except AttributeError:
continue
public = [x for x in items if x in include_public or not x.startswith('_')]
return public, items
except BaseException as e:
print(str(e))
raise e
示例3: get_members
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
def get_members(clazz, obj, typ):
names = set()
items = []
# the default dir
for name in dir(obj):
try:
documenter = get_documenter(safe_getattr(obj, name), obj)
except AttributeError:
continue
if documenter.objtype == typ and not name.startswith('_'):
if name not in AutoCosmoSummary.exclude:
items.append((clazz,name))
names.add(name) # keep track of method/attribute conflicts
# the delegate dro
for n in obj.dro:
for name in dir(n):
try:
documenter = get_documenter(safe_getattr(n, name), n)
except AttributeError:
continue
# dont do conflicts
if name not in names:
if documenter.objtype == typ and not name.startswith('_'):
if name not in AutoCosmoSummary.exclude:
x = "%s.%s" %(n.__module__, n.__name__)
items.append((x,name))
names.add(name)
return ['~%s.%s' %item for item in sorted(items, key=lambda x: x[1])]
示例4: get_members
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
def get_members(obj, typ, public_only=True):
items = []
for name in dir(obj):
if public_only and name.startswith('_'):
continue
try:
documenter = get_documenter(None, safe_getattr(obj, name), obj)
except AttributeError:
continue
if documenter.objtype == typ:
items.append(name)
return items
示例5: get_members
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
def get_members(obj, typ, include_public=None):
if not include_public:
include_public = []
items = []
for name in sorted(obj.__dict__.keys()):#dir(obj):
try:
documenter = get_documenter(AutoAutoSummary.app, safe_getattr(obj, name), obj)
except AttributeError:
continue
if documenter.objtype in typ:
items.append(name)
public = [x for x in items if x in include_public or not x.startswith('_')]
return public, items
示例6: get_members
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
def get_members(app, obj, typ, include_public=(), imported=False):
items = []
for name in dir(obj):
try:
obj_name = safe_getattr(obj, name)
try:
documenter = get_documenter(app, obj_name, obj)
except TypeError:
documenter = get_documenter(obj_name, obj)
except AttributeError:
continue
if documenter.objtype == typ:
try:
cond = imported or (obj_name.__module__ == obj.__name__)
except AttributeError:
cond = True
if cond:
items.append(name)
skip = set(app.config.autosummary_skip_members)
_n = '{}.%s'.format(obj.__name__)
public = [
x for x in items
if (x in include_public or not x.startswith('_')) and _n % x not in skip
]
return public, items
示例7: get_members
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
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
示例8: setup
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [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
示例9: run
# 需要导入模块: from sphinx.ext import autosummary [as 别名]
# 或者: from sphinx.ext.autosummary import get_documenter [as 别名]
def run(self):
module_name = str(self.arguments[0])
module = importlib.import_module(module_name)
analyzer = ModuleAnalyzer.for_module(module_name)
attr_docs = analyzer.find_attr_docs()
with open(module.__file__) as module_file:
symbols = symtable.symtable(module_file.read(), module.__file__, "exec")
members = []
for name in dir(module):
member = getattr(module, name)
# Ignore private members
if name.startswith("_"):
continue
# Ignore imported modules
if isinstance(member, types.ModuleType):
continue
# Ignore members imported from other modules
member_module_name = getattr(member, "__module__", None)
if member_module_name is None:
try:
if symbols.lookup(name).is_imported():
continue
except KeyError:
continue
else:
if member_module_name != module_name:
continue
documenter = get_documenter(self.env.app, member, module)
# Ignore data items that do not have docstrings
if documenter.objtype == "data" and ("", name) not in attr_docs:
continue
members.append(name)
# Sort members in the order they appear in source code
tagorder = analyzer.tagorder
members.sort(key=lambda name: tagorder.get(name, len(tagorder)))
self.content = [f"{module_name}.{member}" for member in members]
return super().run()