本文整理汇总了Python中sphinx.addnodes.desc_signature方法的典型用法代码示例。如果您正苦于以下问题:Python addnodes.desc_signature方法的具体用法?Python addnodes.desc_signature怎么用?Python addnodes.desc_signature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.addnodes
的用法示例。
在下文中一共展示了addnodes.desc_signature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_typehints
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc_signature [as 别名]
def merge_typehints(app: Sphinx, domain: str, objtype: str, contentnode: Element) -> None:
if domain != 'py':
return
if app._autodoc_typehints_description is False: # type: ignore
return
signature = cast(addnodes.desc_signature, contentnode.parent[0])
if signature['module']:
fullname = '.'.join([signature['module'], signature['fullname']])
else:
fullname = signature['fullname']
annotations = app.env.temp_data.get('annotations', {})
if annotations.get(fullname, {}):
field_lists = [n for n in contentnode if isinstance(n, nodes.field_list)]
if field_lists == []:
field_list = insert_field_list(contentnode)
field_lists.append(field_list)
for field_list in field_lists:
modify_field_list(field_list, annotations[fullname])
示例2: get_sections_and_signature
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc_signature [as 别名]
def get_sections_and_signature(need_info):
"""Gets the hierarchy of the section nodes as a list starting at the
section of the current need and then its parent sections"""
sections = []
signature = None
current_node = need_info['target_node']
while current_node:
if isinstance(current_node, nodes.section):
title = current_node.children[0].astext()
# If using auto-section numbering, then Sphinx inserts
# multiple non-breaking space unicode characters into the title
# we'll replace those with a simple space to make them easier to
# use in filters
title = NON_BREAKING_SPACE.sub(' ', title)
sections.append(title)
# Checking for a signature defined "above" the need.
# Used and set normally by directives like automodule.
# Only check as long as we haven't found a signature
if signature is None and current_node.parent is not None and current_node.parent.children is not None:
for sibling in current_node.parent.children:
# We want to check only "above" current node, so no need to check sibling after current_node.
if sibling == current_node:
break
if isinstance(sibling, desc_signature):
# Check the child of the found signature for the text content/node.
for desc_child in sibling.children:
if isinstance(desc_child, desc_name) and \
isinstance(desc_child.children[0], nodes.Text):
signature = desc_child.children[0]
if signature is not None:
break
current_node = getattr(current_node, 'parent', None)
return sections, signature
示例3: make_process_header
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc_signature [as 别名]
def make_process_header(self, slug, typ, version, source_uri, description, inputs):
"""Generate a process definition header.
:param str slug: process' slug
:param str typ: process' type
:param str version: process' version
:param str source_uri: url to the process definition
:param str description: process' description
:param dict inputs: process' inputs
"""
node = addnodes.desc()
signode = addnodes.desc_signature(slug, "")
node.append(signode)
node["objtype"] = node["desctype"] = typ
signode += addnodes.desc_annotation(typ, typ, classes=["process-type"])
signode += addnodes.desc_addname("", "")
signode += addnodes.desc_name(slug + " ", slug + " ")
paramlist = addnodes.desc_parameterlist()
for field_schema, _, _ in iterate_schema({}, inputs, ""):
field_type = field_schema["type"]
field_name = field_schema["name"]
field_default = field_schema.get("default", None)
field_default = "" if field_default is None else "={}".format(field_default)
param = addnodes.desc_parameter("", "", noemph=True)
param += nodes.emphasis(field_type, field_type, classes=["process-type"])
# separate by non-breaking space in the output
param += nodes.strong(text="\xa0\xa0" + field_name)
paramlist += param
signode += paramlist
signode += nodes.reference(
"",
nodes.Text("[Source: v{}]".format(version)),
refuri=source_uri,
classes=["viewcode-link"],
)
desc = nodes.paragraph()
desc += nodes.Text(description, description)
return [node, desc]
示例4: doctree_read
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc_signature [as 别名]
def doctree_read(app, doctree):
# Get the configuration parameters
if app.config.edit_on_github_project == 'REQUIRED':
raise ValueError(
"The edit_on_github_project configuration variable must be "
"provided in the conf.py")
source_root = app.config.edit_on_github_source_root
url = get_url_base(app)
docstring_message = app.config.edit_on_github_docstring_message
# Handle the docstring-editing links
for objnode in doctree.traverse(addnodes.desc):
if objnode.get('domain') != 'py':
continue
names = set()
for signode in objnode:
if not isinstance(signode, addnodes.desc_signature):
continue
modname = signode.get('module')
if not modname:
continue
fullname = signode.get('fullname')
if fullname in names:
# only one link per name, please
continue
names.add(fullname)
obj = import_object(modname, fullname)
anchor = None
if obj is not None:
try:
lines, lineno = inspect.getsourcelines(obj)
except:
pass
else:
anchor = '#L%d' % lineno
if anchor:
real_modname = inspect.getmodule(obj).__name__
path = '%s%s%s.py%s' % (
url, source_root, real_modname.replace('.', '/'), anchor)
onlynode = addnodes.only(expr='html')
onlynode += nodes.reference(
reftitle=app.config.edit_on_github_help_message,
refuri=path)
onlynode[0] += nodes.inline(
'', '', nodes.raw('', ' ', format='html'),
nodes.Text(docstring_message),
classes=['edit-on-github', 'viewcode-link'])
signode += onlynode
示例5: doctree_read
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc_signature [as 别名]
def doctree_read(app, doctree):
env = app.builder.env
resolve_target = getattr(env.config, 'linkcode_resolve', None)
if not isinstance(env.config.linkcode_resolve, collections.Callable):
raise LinkcodeError(
"Function `linkcode_resolve` is not given in conf.py")
domain_keys = dict(
py=['module', 'fullname'],
c=['names'],
cpp=['names'],
js=['object', 'fullname'],
)
for objnode in doctree.traverse(addnodes.desc):
domain = objnode.get('domain')
uris = set()
for signode in objnode:
if not isinstance(signode, addnodes.desc_signature):
continue
# Convert signode to a specified format
info = {}
for key in domain_keys.get(domain, []):
value = signode.get(key)
if not value:
value = ''
info[key] = value
if not info:
continue
# Call user code to resolve the link
uri = resolve_target(domain, info)
if not uri:
# no source
continue
if uri in uris or not uri:
# only one link per name, please
continue
uris.add(uri)
onlynode = addnodes.only(expr='html')
onlynode += nodes.reference('', '', internal=False, refuri=uri)
onlynode[0] += nodes.inline('', _('[source]'),
classes=['viewcode-link'])
signode += onlynode