本文整理汇总了Python中sphinx.addnodes.only函数的典型用法代码示例。如果您正苦于以下问题:Python only函数的具体用法?Python only怎么用?Python only使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了only函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
from docutils import nodes
from sphinx import addnodes
from sphinx.util.nodes import set_source_info
node = addnodes.only()
node.document = self.state.document
set_source_info(self, node)
node['expr'] = self.arguments[0]
# hack around title style bookkeeping
surrounding_title_styles = self.state.memo.title_styles
surrounding_section_level = self.state.memo.section_level
self.state.memo.title_styles = []
self.state.memo.section_level = 0
try:
result = self.state.nested_parse(self.content, 0, node,
match_titles=1)
depth = len(surrounding_title_styles)
if self.state.memo.title_styles:
style = self.state.memo.title_styles[0]
if style in surrounding_title_styles:
depth = surrounding_title_styles.index(style)
parent = self.state.parent
for i in xrange(len(surrounding_title_styles) - depth):
if parent.parent:
parent = parent.parent
parent.append(node)
finally:
self.state.memo.title_styles = surrounding_title_styles
self.state.memo.section_level = surrounding_section_level
return []
开发者ID:oci1315,项目名称:oci-poo,代码行数:32,代码来源:conf.py
示例2: run
def run(self):
doc = self.state.document
env = doc.settings.env
if 'layout' in self.options:
layout = self.options['layout']
else:
layout = env.config.demo_layout
if not self.layout_re.match(layout):
return [doc.reporter.error("invalid layout specifier: %s" % layout,
lineno=self.lineno)]
order = []
for block in layout.split(','):
block = block.strip()
is_hidden = block[0] == '-'
block = block.lstrip('+-')
order.append((block, is_hidden))
wrapper = nodes.compound(classes=['demo-wrapper'])
data = "\n".join(self.content)
for block, is_hidden in order:
if block == 'demo':
header = nodes.paragraph(classes=['demo-header'])
header += nodes.Text("Demo")
if is_hidden:
header['classes'].append('demo-hide')
demo = nodes.raw(data, data,
format='html',
classes=['demo-area'])
html_wrapper = addnodes.only(expr='html')
html_wrapper += header
html_wrapper += demo
wrapper += html_wrapper
elif block == 'source':
header = nodes.paragraph(classes=['demo-header'])
header += nodes.Text("Source")
if is_hidden:
header['classes'].append('demo-hide')
source = nodes.literal_block(data, data,
language='html',
classes=['demo-source'])
html_wrapper = addnodes.only(expr='html')
html_wrapper += header
wrapper += html_wrapper
wrapper += source
else:
assert False, block
return [wrapper]
开发者ID:Ontomatica,项目名称:Nutrition-Database-Modernization,代码行数:46,代码来源:jsdemo.py
示例3: run
def run(self):
node = addnodes.only()
node.document = self.state.document
node.line = self.lineno
node['expr'] = self.arguments[0]
self.state.nested_parse(self.content, self.content_offset, node,
match_titles=1)
return [node]
开发者ID:hurtado452,项目名称:battleAtSea-master,代码行数:8,代码来源:other.py
示例4: doctree_read
def doctree_read(app, doctree):
env = app.builder.env
if not hasattr(env, '_viewcode_modules'):
env._viewcode_modules = {}
def has_tag(modname, fullname, docname, refname):
entry = env._viewcode_modules.get(modname, None)
try:
analyzer = ModuleAnalyzer.for_module(modname)
except Exception:
env._viewcode_modules[modname] = False
return
if not isinstance(analyzer.code, text_type):
code = analyzer.code.decode(analyzer.encoding)
else:
code = analyzer.code
if entry is None or entry[0] != code:
analyzer.find_tags()
entry = code, analyzer.tags, {}, refname
env._viewcode_modules[modname] = entry
elif entry is False:
return
_, tags, used, _ = entry
if fullname in tags:
used[fullname] = docname
return True
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')
fullname = signode.get('fullname')
refname = modname
if env.config.viewcode_import:
modname = _get_full_modname(app, modname, fullname)
if not modname:
continue
fullname = signode.get('fullname')
if not has_tag(modname, fullname, env.docname, refname):
continue
if fullname in names:
# only one link per name, please
continue
names.add(fullname)
pagename = '_modules/' + modname.replace('.', '/')
onlynode = addnodes.only(expr='html')
onlynode += addnodes.pending_xref(
'', reftype='viewcode', refdomain='std', refexplicit=False,
reftarget=pagename, refid=fullname,
refdoc=env.docname)
onlynode[0] += nodes.inline('', _('[source]'),
classes=['viewcode-link'])
signode += onlynode
开发者ID:lehmannro,项目名称:sphinx-mirror,代码行数:57,代码来源:viewcode.py
示例5: doctree_read
def doctree_read(app, doctree):
env = app.builder.env
if not hasattr(env, "_viewcode_modules"):
env._viewcode_modules = {}
def has_tag(modname, fullname, docname):
entry = env._viewcode_modules.get(modname, None)
try:
analyzer = ModuleAnalyzer.for_module(modname)
except Exception:
env._viewcode_modules[modname] = False
return
if not isinstance(analyzer.code, str):
code = analyzer.code.decode(analyzer.encoding)
else:
code = analyzer.code
if entry is None or entry[0] != code:
analyzer.find_tags()
entry = code, analyzer.tags, {}
env._viewcode_modules[modname] = entry
elif entry is False:
return
code, tags, used = entry
if fullname in tags:
used[fullname] = docname
return True
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 not has_tag(modname, fullname, env.docname):
continue
if fullname in names:
# only one link per name, please
continue
names.add(fullname)
pagename = "_modules/" + modname.replace(".", "/")
onlynode = addnodes.only(expr="html")
onlynode += addnodes.pending_xref(
"",
reftype="viewcode",
refdomain="std",
refexplicit=False,
reftarget=pagename,
refid=fullname,
refdoc=env.docname,
)
onlynode[0] += nodes.inline("", _("[source]"), classes=["viewcode-link"])
signode += onlynode
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:57,代码来源:viewcode.py
示例6: doctree_read
def doctree_read(app, doctree):
# Add viewcode nodes for code elements referenced in the document.
env = app.builder.env
if not hasattr(env, '_viewcode_modules'):
env._viewcode_modules = {}
# handle desc (description) nodes (module contents)
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 not _update_tags(env, modname, fullname):
continue
if fullname in names:
# only one link per name, please
continue
names.add(fullname)
pagename = '_modules/' + modname.replace('.', '/')
# build up an xref and add it to the desc node
onlynode = addnodes.only(expr='html')
onlynode += addnodes.pending_xref(
'', reftype='viewcode', refdomain='std', refexplicit=False,
reftarget=pagename, refid=fullname,
refdoc=env.docname)
onlynode[0] += nodes.inline('', _('[source]'),
classes=['viewcode-link'])
signode += onlynode
# handle index nodes (modules themselves)
for objnode in doctree.traverse(addnodes.index):
# extract module name by de-munging the "target" field
index_target = objnode['entries'][0][2]
if not index_target.startswith('module-'):
continue
modname = index_target.replace('module-', '', 1)
_update_tags(env, modname)
pagename = '_modules/' + modname.replace('.', '/')
# build up an xref and add it in a new paragraph after the index node
xref = addnodes.pending_xref(
'', reftype='viewcode', refdomain='std', refexplicit=False,
reftarget=pagename, refid='', refdoc=env.docname)
xref += nodes.inline('', _('[source]'),
classes=['viewcode-link'])
idx = objnode.parent.index(objnode) + 1
objnode.parent.insert(idx, nodes.paragraph('', '', xref))
开发者ID:LoLab-VU,项目名称:earm,代码行数:53,代码来源:viewcode.py
示例7: doctree_read
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
开发者ID:LaurethTeX,项目名称:astropy,代码行数:50,代码来源:edit_on_github.py
示例8: doctree_read
def doctree_read(app, doctree):
# type: (Sphinx, nodes.Node) -> None
env = app.builder.env
resolve_target = getattr(env.config, 'linkcode_resolve', None)
if not callable(env.config.linkcode_resolve):
raise LinkcodeError(
"Function `linkcode_resolve` is not given in conf.py")
domain_keys = {
'py': ['module', 'fullname'],
'c': ['names'],
'cpp': ['names'],
'js': ['object', 'fullname'],
}
for objnode in doctree.traverse(addnodes.desc):
domain = objnode.get('domain')
uris = set() # type: Set[str]
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
if 'lineno' in signode.attributes:
info['lineno'] = signode.attributes['lineno']
# 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)
inline = nodes.inline('', _('[source]'), classes=['viewcode-link'])
onlynode = addnodes.only(expr='html')
onlynode += nodes.reference('', '', inline, internal=False, refuri=uri)
signode += onlynode
开发者ID:googlefonts,项目名称:fontbakery,代码行数:50,代码来源:linkcode.py
示例9: doctree_read
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
开发者ID:5i7788,项目名称:pandas,代码行数:48,代码来源:linkcode.py
示例10: build_toc
def build_toc(node, depth=1):
# type: (nodes.Element, int) -> nodes.bullet_list
entries = [] # type: List[nodes.Element]
for sectionnode in node:
# find all toctree nodes in this section and add them
# to the toc (just copying the toctree node which is then
# resolved in self.get_and_resolve_doctree)
if isinstance(sectionnode, nodes.section):
title = sectionnode[0]
# copy the contents of the section title, but without references
# and unnecessary stuff
visitor = SphinxContentsFilter(doctree)
title.walkabout(visitor)
nodetext = visitor.get_entry_text()
if not numentries[0]:
# for the very first toc entry, don't add an anchor
# as it is the file's title anyway
anchorname = ''
else:
anchorname = '#' + sectionnode['ids'][0]
numentries[0] += 1
# make these nodes:
# list_item -> compact_paragraph -> reference
reference = nodes.reference(
'', '', internal=True, refuri=docname,
anchorname=anchorname, *nodetext)
para = addnodes.compact_paragraph('', '', reference)
item = nodes.list_item('', para) # type: nodes.Element
sub_item = build_toc(sectionnode, depth + 1)
if sub_item:
item += sub_item
entries.append(item)
elif isinstance(sectionnode, addnodes.only):
onlynode = addnodes.only(expr=sectionnode['expr'])
blist = build_toc(sectionnode, depth)
if blist:
onlynode += blist.children
entries.append(onlynode)
elif isinstance(sectionnode, nodes.Element):
for toctreenode in traverse_in_section(sectionnode,
addnodes.toctree):
item = toctreenode.copy()
entries.append(item)
# important: do the inventory stuff
TocTree(app.env).note(docname, toctreenode)
if entries:
return nodes.bullet_list('', *entries)
return None
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:48,代码来源:toctree.py
示例11: run
def run(self):
# type: () -> List[nodes.Node]
node = addnodes.only()
node.document = self.state.document
set_source_info(self, node)
node['expr'] = self.arguments[0]
# Same as util.nested_parse_with_titles but try to handle nested
# sections which should be raised higher up the doctree.
memo = self.state.memo # type: Any
surrounding_title_styles = memo.title_styles
surrounding_section_level = memo.section_level
memo.title_styles = []
memo.section_level = 0
try:
self.state.nested_parse(self.content, self.content_offset,
node, match_titles=True)
title_styles = memo.title_styles
if (not surrounding_title_styles or
not title_styles or
title_styles[0] not in surrounding_title_styles or
not self.state.parent):
# No nested sections so no special handling needed.
return [node]
# Calculate the depths of the current and nested sections.
current_depth = 0
parent = self.state.parent
while parent:
current_depth += 1
parent = parent.parent
current_depth -= 2
title_style = title_styles[0]
nested_depth = len(surrounding_title_styles)
if title_style in surrounding_title_styles:
nested_depth = surrounding_title_styles.index(title_style)
# Use these depths to determine where the nested sections should
# be placed in the doctree.
n_sects_to_raise = current_depth - nested_depth + 1
parent = cast(nodes.Element, self.state.parent)
for i in range(n_sects_to_raise):
if parent.parent:
parent = parent.parent
parent.append(node)
return []
finally:
memo.title_styles = surrounding_title_styles
memo.section_level = surrounding_section_level
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:47,代码来源:other.py
示例12: build_toc
def build_toc(node, depth=1, main=False, title_visited=False):
entries = []
for sectionnode in node:
# EV: added or condition on 'main' and 'title_visited'
# find all toctree nodes in this section and add them
# to the toc (just copying the toctree node which is then
# resolved in self.get_and_resolve_doctree)
if isinstance(sectionnode, addnodes.only):
onlynode = addnodes.only(expr=sectionnode['expr'])
blist = build_toc(sectionnode, depth)
if blist:
onlynode += blist.children
entries.append(onlynode)
if not isinstance(sectionnode, nodes.section) or (main and title_visited):
for toctreenode in traverse_in_section(sectionnode,
addnodes.toctree):
item = toctreenode.copy()
entries.append(item)
# important: do the inventory stuff
self.note_toctree(docname, toctreenode)
continue
title = sectionnode[0]
# copy the contents of the section title, but without references
# and unnecessary stuff
visitor = SphinxContentsFilter(document)
title.walkabout(visitor)
nodetext = visitor.get_entry_text()
if not numentries[0]:
# for the very first toc entry, don't add an anchor
# as it is the file's title anyway
anchorname = ''
else:
anchorname = '#' + sectionnode['ids'][0]
numentries[0] += 1
reference = nodes.reference(
'', '', internal=True, refuri=docname,
anchorname=anchorname, *nodetext)
para = addnodes.compact_paragraph('', '', reference)
item = nodes.list_item('', para)
if maxdepth == 0 or depth < maxdepth:
# EV: set 'main' and 'title_visited' args
item += build_toc(sectionnode, depth+1, main=main, title_visited=True)
entries.append(item)
if entries:
return nodes.bullet_list('', *entries)
return []
开发者ID:baohaojun,项目名称:eclim,代码行数:46,代码来源:environment.py
示例13: run
def run(self):
node = addnodes.only()
node.document = self.state.document
set_source_info(self, node)
node['expr'] = 'iguide'
class_value = ['iguide', self.arguments[0]]
pending = nodes.pending(misc.ClassAttribute,
{'class': class_value,
'directive': self.name},
self.block_text)
self.state_machine.document.note_pending(pending)
node += pending
self.state.nested_parse(self.content, self.content_offset, node,
match_titles=1)
return [node]
开发者ID:victerryso,项目名称:flip_the_mrs,代码行数:18,代码来源:instructor_guide.py
示例14: doctree_read
def doctree_read(app, doctree):
env = app.builder.env
resolve_target = getattr(env.config, "linkcode_resolve", None)
if not callable(env.config.linkcode_resolve):
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
开发者ID:861008761,项目名称:standard_flask_web,代码行数:41,代码来源:linkcode.py
示例15: doctree_read
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
if source_root != '' and not source_root.endswith('/'):
source_root += '/'
doc_root = app.config.edit_on_github_doc_root
if doc_root != '' and not doc_root.endswith('/'):
doc_root += '/'
url = 'http://github.com/%s/tree/%s/' % (
app.config.edit_on_github_project,
app.config.edit_on_github_branch)
docstring_message = app.config.edit_on_github_docstring_message
page_message = app.config.edit_on_github_page_message
# Handle the "edit this page" link
doc_path = os.path.relpath(doctree.get('source'), app.builder.srcdir)
if not re.match(app.config.edit_on_github_skip_regex, doc_path):
path = url + doc_root + doc_path
onlynode = addnodes.only(expr='html')
onlynode += nodes.reference(
reftitle=app.config.edit_on_bitbucket_help_message, refuri=path)
onlynode[0] += nodes.inline(
'', page_message, classes=['edit-on-github'])
para = nodes.paragraph()
para.update_basic_atts({'classes':['edit-on-github-para']})
para += onlynode
if 'edit-section' in doctree[-1].attributes['classes']:
doctree[-1] += para
else:
section = nodes.section()
section.update_basic_atts({'classes':['edit-section']})
section += para
doctree += section
# 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:
path = '%s%s%s.py%s' % (
url, source_root, 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
开发者ID:BrunoValeFernandes,项目名称:pyspeckit,代码行数:77,代码来源:edit_on_github.py
示例16: doctree_read
def doctree_read(app, doctree):
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 == 'class':
cls = getattr(module, object_name, None)
if cls is None:
continue
if cls not in classes_to_attributes:
classes_to_attributes[cls] = {}
attributes = inspect.classify_class_attrs(cls)
for attribute in attributes:
classes_to_attributes[cls][attribute.name] = attribute
if inspect.isabstract(cls):
labelnode = addnodes.only(expr='html')
labelnode.append(nodes.emphasis(
'abstract ',
'abstract ',
classes=['property'],
))
signature_node.insert(0, labelnode)
elif object_type in ('method', 'attribute', 'staticmethod', 'classmethod'):
cls_name, attr_name = object_name.split('.')
cls = getattr(module, cls_name, None)
if cls is None:
continue
attr = getattr(cls, attr_name)
inspected_attr = classes_to_attributes[cls][attr_name]
label_node = addnodes.only(expr='html')
defining_class = inspected_attr.defining_class
if defining_class != cls:
addname_node = signature_node.traverse(
addnodes.desc_addname)[0]
if defining_class.__module__.startswith('supriya'):
reftarget = defining_class.__module__
else:
reftarget = '{}.{}'.format(
defining_class.__module__,
defining_class.__name__,
)
xref_node = addnodes.pending_xref(
'',
refdomain='py',
refexplicit=True,
reftype='class',
reftarget=reftarget,
)
xref_node.append(nodes.literal(
'',
'{}'.format(defining_class.__name__),
classes=['descclassname'],
))
html_only_class_name_node = addnodes.only(expr='html')
html_only_class_name_node.append(nodes.Text('('))
html_only_class_name_node.append(xref_node)
html_only_class_name_node.append(nodes.Text(').'))
latex_only_class_name_node = addnodes.only(expr='latex')
latex_only_class_name_node.append(nodes.Text(
'({}).'.format(defining_class.__name__),
))
addname_node.clear()
addname_node.append(html_only_class_name_node)
addname_node.append(latex_only_class_name_node)
#label_node.append(nodes.emphasis(
# 'inherited ',
# 'inherited ',
# classes=['property'],
# ))
if getattr(attr, '__isabstractmethod__', False):
label_node.append(nodes.emphasis(
'abstract ',
'abstract ',
classes=['property'],
))
if hasattr(attr, 'im_self') and attr.im_self is not None:
signature_node.pop(0)
label_node.append(nodes.emphasis(
'classmethod ',
'classmethod ',
classes=['property'],
#.........这里部分代码省略.........
开发者ID:andrewyoung1991,项目名称:supriya,代码行数:101,代码来源:style.py
示例17: doctree_read
def doctree_read(app, doctree):
env = app.builder.env
if not hasattr(env, '_viewcode_modules'):
env._viewcode_modules = {}
def get_full_modname(modname, attribute):
try:
__import__(modname)
except Exception as error:
if not app.quiet:
app.info(traceback.format_exc().rstrip())
app.warn('viewcode can\'t import %s, failed with error "%s"' %
(modname, error))
return None
module = sys.modules[modname]
try:
# Allow an attribute to have multiple parts and incidentally allow
# repeated .s in the attribute.
attr = attribute.split('.')
value = module
for attr in attribute.split('.'):
if attr:
value = safe_getattr(value, attr)
except AttributeError:
app.warn('Didn\'t find %s in %s' % (attribute, module.__name__))
return None
else:
return safe_getattr(value, '__module__', None)
def has_tag(modname, fullname, docname, refname):
entry = env._viewcode_modules.get(modname, None)
if entry is None:
try:
analyzer = ModuleAnalyzer.for_module(modname)
except Exception:
env._viewcode_modules[modname] = False
return
analyzer.find_tags()
if not isinstance(analyzer.code, text_type):
code = analyzer.code.decode(analyzer.encoding)
else:
code = analyzer.code
entry = code, analyzer.tags, {}, refname
env._viewcode_modules[modname] = entry
elif entry is False:
return
_, tags, used, _ = entry
if fullname in tags:
used[fullname] = docname
return True
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')
fullname = signode.get('fullname')
refname = modname
if env.config.viewcode_import:
modname = get_full_modname(modname, fullname)
if not modname:
continue
if not has_tag(modname, fullname, env.docname, refname):
continue
if fullname in names:
# only one link per name, please
continue
names.add(fullname)
pagename = '_modules/' + modname.replace('.', '/')
onlynode = addnodes.only(expr='html')
onlynode += addnodes.pending_xref(
'', reftype='viewcode', refdomain='std', refexplicit=False,
reftarget=pagename, refid=fullname,
refdoc=env.docname)
onlynode[0] += nodes.inline('', _('[source]'),
classes=['viewcode-link'])
signode += onlynode
开发者ID:Punyaslok,项目名称:astropy-helpers,代码行数:82,代码来源:viewcode.py
示例18: doctree_read
def doctree_read(app, doctree):
# type: (Sphinx, nodes.Node) -> None
env = app.builder.env
if not hasattr(env, '_viewcode_modules'):
env._viewcode_modules = {} # type: ignore
if app.builder.name == "singlehtml":
return
if app.builder.name.startswith("epub") and not env.config.viewcode_enable_epub:
return
def has_tag(modname, fullname, docname, refname):
entry = env._viewcode_modules.get(modname, None) # type: ignore
if entry is False:
return
code_tags = app.emit_firstresult('viewcode-find-source', modname)
if code_tags is None:
try:
analyzer = ModuleAnalyzer.for_module(modname)
except Exception:
env._viewcode_modules[modname] = False # type: ignore
return
if not isinstance(analyzer.code, text_type):
code = analyzer.code.decode(analyzer.encoding)
else:
code = analyzer.code
analyzer.find_tags()
tags = analyzer.tags
else:
code, tags = code_tags
if entry is None or entry[0] != code:
entry = code, tags, {}, refname
env._viewcode_modules[modname] = entry # type: ignore
_, tags, used, _ = entry
if fullname in tags:
used[fullname] = docname
return True
for objnode in doctree.traverse(addnodes.desc):
if objnode.get('domain') != 'py':
continue
names = set() # type: Set[unicode]
for signode in objnode:
if not isinstance(signode, addnodes.desc_signature):
continue
modname = signode.get('module')
fullname = signode.get('fullname')
refname = modname
if env.config.viewcode_follow_imported_members:
new_modname = app.emit_firstresult(
'viewcode-follow-imported', modname, fullname,
)
if not new_modname:
new_modname = _get_full_modname(app, modname, fullname)
modname = new_modname
if not modname:
continue
fullname = signode.get('fullname')
if not has_tag(modname, fullname, env.docname, refname):
continue
if fullname in names:
# only one link per name, please
continue
names.add(fullname)
pagename = '_modules/' + modname.replace('.', '/')
onlynode = addnodes.only(expr='html')
onlynode += addnodes.pending_xref(
'', reftype='viewcode', refdomain='std', refexplicit=False,
reftarget=pagename, refid=fullname,
refdoc=env.docname)
onlynode[0] += nodes.inline('', _('[source]'),
classes=['viewcode-link'])
signode += onlynode
开发者ID:sam-m888,项目名称:sphinx,代码行数:76,代码来源:viewcode.py
示例19: get_full_modname
continue
modname = signode.get('module')
fullname = signode.get('fullname')
refname = modname
if env.config.viewcode_import:
modname = get_full_modname(modname, fu
|
请发表评论