Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
classes_to_attributes = {}
def get_unique_parts(parts):
unique_parts = [parts[0]]
for part in parts[1:]:
if part != unique_parts[-1]:
unique_parts.append(part)
else:
break
return unique_parts
for desc_node in doctree.traverse(addnodes.desc):
if desc_node.get('domain') != 'py':
continue
signature_node = desc_node.traverse(addnodes.desc_signature)[0]
module_name = signature_node.get('module')
object_name = signature_node.get('fullname')
object_type = desc_node.get('objtype')
module = importlib.import_module(module_name)
if object_type in ('function', 'class'):
addname_node = signature_node.traverse(addnodes.desc_addname)[0]
text = addname_node[0].astext()
parts = [x for x in text.split('.') if x]
parts = get_unique_parts(parts)
if parts[0] in ('abjad', 'experimental', 'ide'):
parts = parts[-1:]
if parts:
text = '{}.'.format('.'.join(parts))
else:
text = ''
def _toctree_prune(self, node: Element, depth: int, maxdepth: int, collapse: bool = False
) -> None:
"""Utility: Cut a TOC at a specified depth."""
for subnode in node.children[:]:
if isinstance(subnode, (addnodes.compact_paragraph,
nodes.list_item)):
# for <p> and </p><li>, just recurse
self._toctree_prune(subnode, depth, maxdepth, collapse)
elif isinstance(subnode, nodes.bullet_list):
# for <ul>, determine if the depth is too large or if the
# entry is to be collapsed
if maxdepth > 0 and depth > maxdepth:
subnode.parent.replace(subnode, [])
else:
# cull sub-entries whose parents aren't 'current'
if (collapse and depth > 1 and
'iscurrent' not in subnode.parent):
subnode.parent.remove(subnode)
else:
# recurse on visible children
self._toctree_prune(subnode, depth + 1, maxdepth, collapse)</ul></li>
if self.display_prefix:
signode += addnodes.desc_annotation(self.display_prefix,
self.display_prefix)
for prefix in ['public', 'protected', 'static']:
if prefix in self.options:
signode += addnodes.desc_annotation(prefix + ' ',
prefix + ' ')
# Show prefix only on shorter declarations
if sig.prefix is not None and not self.has_arguments:
signode += addnodes.desc_addname(sig.prefix + '.', sig.prefix + '.')
signode += addnodes.desc_name(sig.member, sig.member)
if self.has_arguments:
if not sig.arguments:
signode += addnodes.desc_parameterlist()
else:
# TODO replace this
_pseudo_parse_arglist(signode, ', '.join(sig.arguments))
if isinstance(self, DotNetObjectNested):
return sig.full_name(), sig.full_name()
return sig.full_name(), sig.prefix
def handle_signature(self, sig, signode):
signode += addnodes.desc_addname(sig, sig)
return sig
def _get_table(self, objects):
table_spec = addnodes.tabular_col_spec()
table_spec["spec"] = r"p{0.5\linewidth}p{0.5\linewidth}"
table = sphinx.ext.autosummary.autosummary_table("")
real_table = nodes.table("", classes=["longtable"])
table.append(real_table)
group = nodes.tgroup("", cols=2)
real_table.append(group)
group.append(nodes.colspec("", colwidth=10))
group.append(nodes.colspec("", colwidth=90))
body = nodes.tbody("")
group.append(body)
for obj in objects:
body.append(self._get_row(obj))
return [table_spec, table]
new_cite_ref_rawsources = [ref.rawsource for ref in new_cite_refs]
logger.warning('inconsistent citation references in translated message.' +
' original: {0}, translated: {1}'
.format(old_cite_ref_rawsources, new_cite_ref_rawsources),
location=node)
for old in old_cite_refs:
refname_ids_map[old["refname"]] = old["ids"]
for new in new_cite_refs:
refname = new["refname"]
if refname in refname_ids_map:
new["ids"] = refname_ids_map[refname]
# Original pending_xref['reftarget'] contain not-translated
# target name, new pending_xref must use original one.
# This code restricts to change ref-targets in the translation.
old_refs = node.traverse(addnodes.pending_xref)
new_refs = patch.traverse(addnodes.pending_xref)
xref_reftarget_map = {}
if len(old_refs) != len(new_refs):
old_ref_rawsources = [ref.rawsource for ref in old_refs]
new_ref_rawsources = [ref.rawsource for ref in new_refs]
logger.warning('inconsistent term references in translated message.' +
' original: {0}, translated: {1}'
.format(old_ref_rawsources, new_ref_rawsources),
location=node)
def get_ref_key(node):
# type: (nodes.Node) -> Tuple[unicode, unicode, unicode]
case = node["refdomain"], node["reftype"]
if case == ('std', 'term'):
return None
else:
# exceptions are a special case, since they are documented in the
# 'exceptions' package.
elif add_package and self.env.config.add_module_names:
pkgname = self.options.get(
'package', self.env.ref_context.get('go:package'))
if pkgname and pkgname != 'exceptions':
nodetext = pkgname + '/'
signode += addnodes.desc_addname(nodetext, nodetext)
anno = self.options.get('annotation')
signode += addnodes.desc_name(name, name)
if not arglist:
if self.needs_arglist():
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_returns(retann, retann)
if anno:
signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)
return fullname, name_prefix
_pseudo_parse_arglist(signode, arglist)
if retann:
signode += addnodes.desc_returns(retann, retann)
if anno:
signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)
return fullname, name_prefix
def is_compact_paragraph(self, node):
parent = node.parent
if isinstance(parent, (nodes.document, nodes.compound,
addnodes.desc_content,
addnodes.versionmodified)):
# Never compact paragraphs in document or compound.
return False
for key, value in node.attlist():
# we can ignore a few specific classes, all other non-default
# attributes require that a <p> node remains
if key != 'classes' or value not in ([], ['first'], ['last'], ['first', 'last']):
return False
first = isinstance(node.parent[0], nodes.label)
for child in parent.children[first:]:
# only first paragraph can be compact
if isinstance(child, nodes.Invisible):
continue
if child is node:</p>
def visit_paragraph(self, node):
if not isinstance(node.parent, nodes.Admonition) or \
isinstance(node.parent, addnodes.seealso):
self.new_state(0)