本文整理汇总了Python中sphinx.roles.XRefRole方法的典型用法代码示例。如果您正苦于以下问题:Python roles.XRefRole方法的具体用法?Python roles.XRefRole怎么用?Python roles.XRefRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.roles
的用法示例。
在下文中一共展示了roles.XRefRole方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from sphinx import roles [as 别名]
# 或者: from sphinx.roles import XRefRole [as 别名]
def setup(app):
app.add_config_value('number_figures', True, True)
app.add_config_value('figure_caption_prefix', "Figure", True)
app.add_node(page_ref,
text=(skip_page_ref, None),
html=(skip_page_ref, None),
latex=(latex_visit_page_ref, None))
app.add_role('page', XRefRole(nodeclass=page_ref))
app.add_node(num_ref,
latex=(latex_visit_num_ref, None))
app.add_role('num', XRefRole(nodeclass=num_ref))
app.connect("builder-inited", clean_env)
app.connect('doctree-read', doctree_read)
app.connect('doctree-resolved', doctree_resolved)
示例2: brianobj_role
# 需要导入模块: from sphinx import roles [as 别名]
# 或者: from sphinx.roles import XRefRole [as 别名]
def brianobj_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
'''
A Sphinx role, used as a wrapper for the default `py:obj` role, allowing
us to use the simple backtick syntax for brian classes/functions without
having to qualify the package for classes/functions that are available after
a `from brian2 import *`, e.g `NeuronGroup`.
Also allows to directly link to preference names using the same syntax.
'''
if text in prefs:
linktext = text.replace('_', '-').replace('.', '-')
text = '%s <brian-pref-%s>' % (text, linktext)
# Use sphinx's cross-reference role
xref = XRefRole(warn_dangling=True)
return xref('std:ref', rawtext, text, lineno, inliner, options, content)
else:
if text and (not '~' in text):
try:
# A simple class or function name
if not '.' in text:
module = __import__('brian2genn', fromlist=[str(text)])
imported = getattr(module, str(text), None)
if hasattr(imported, '__module__'):
text = '~' + imported.__module__ + '.' + text
if inspect.isfunction(imported):
text += '()'
# Possibly a method/classmethod/attribute name
elif len(text.split('.')) == 2:
classname, attrname = text.split('.')
# Remove trailing parentheses (will be readded for display)
if attrname.endswith('()'):
attrname = attrname[:-2]
module = __import__('brian2genn', fromlist=[str(classname)])
imported = getattr(module, str(classname), None)
if hasattr(imported, '__module__'):
# Add trailing parentheses only for methods not for
# attributes
if inspect.ismethod(getattr(imported,
str(attrname),
None)):
parentheses = '()'
else:
parentheses = ''
text = ('{classname}.{attrname}{parentheses} '
'<{modname}.{classname}.{attrname}>').format(classname=classname,
attrname=attrname,
modname=imported.__module__,
parentheses=parentheses)
except ImportError:
pass
role = 'py:obj'
py_role = PyXRefRole()
return py_role(role, rawtext, text, lineno, inliner, options, content)