Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sphinx超链接到在别名下导入的Python模块的成员_Python_Python Sphinx - Fatal编程技术网

sphinx超链接到在别名下导入的Python模块的成员

sphinx超链接到在别名下导入的Python模块的成员,python,python-sphinx,Python,Python Sphinx,我维护了一个Python包,它通常以import numpy as np或import pandas as pd的方式使用一个简短的标准化昵称导入。假设它是作为fb导入foobar 我正在使用sphinx来记录它,在我的conf.py中,我的扩展中有'sphinx.ext.autodoc',以及默认角色='py:obj'。这是一个很好的设置,因为它意味着每当我的docstrings或separate.rst文件包含一个像 See the `foobar.Thing` class document

我维护了一个Python包,它通常以
import numpy as np
import pandas as pd
的方式使用一个简短的标准化昵称导入。假设它是
作为fb导入foobar

我正在使用sphinx来记录它,在我的
conf.py
中,我的
扩展中有
'sphinx.ext.autodoc'
,以及
默认角色='py:obj'
。这是一个很好的设置,因为它意味着每当我的docstrings或separate
.rst
文件包含一个像

See the `foobar.Thing` class documentation for more details. 
甚至只是

See the `Thing` class documentation for more details.
然后backticks中的文本自动超链接到
foobar.Thing
类的文档。但缺少的是这样做的能力:

See the `fb.Thing` class documentation for more details.
文本
fb.Thing
没有超链接,因为sphinx(或sphinx autodoc)不知道
fb
foobar
包的别名。我该怎么说呢

注意:我知道可以使用
符号:

See the `fb.Thing <foobar.Thing>` class documentation for more details.
有关更多详细信息,请参阅'fb.Thing'类文档。

但是docstring也被设计为以纯文本的形式读取,所以我希望这可以在不引入这种或其他形式的
:混乱:`…`
的情况下完成,而是以某种方式在
conf.py
文件或
.automodule::
语句中完成。

这可以通过intersphinx解决。如果在本地对象资源清册中找不到名称,它可以在外部源中搜索。您可以将自己的文档添加为intersphinx清单

Intersphinx配置:

# ==============================================================================
# Sphinx.Ext.InterSphinx
# ==============================================================================
intersphinx_mapping = {
#  'python':       ('https://docs.python.org/3', None),
  'foobar': ('http://foobar.readthedocs.io/en/latest', None),
}
At next, I want to document `fb.Thing <foobar:Thing>`, because it's a great implementation.
用法:

# ==============================================================================
# Sphinx.Ext.InterSphinx
# ==============================================================================
intersphinx_mapping = {
#  'python':       ('https://docs.python.org/3', None),
  'foobar': ('http://foobar.readthedocs.io/en/latest', None),
}
At next, I want to document `fb.Thing <foobar:Thing>`, because it's a great implementation.
接下来,我想记录'fb.Thing',因为它是一个很好的实现。
更多资源:

# ==============================================================================
# Sphinx.Ext.InterSphinx
# ==============================================================================
intersphinx_mapping = {
#  'python':       ('https://docs.python.org/3', None),
  'foobar': ('http://foobar.readthedocs.io/en/latest', None),
}
At next, I want to document `fb.Thing <foobar:Thing>`, because it's a great implementation.
  • Intersphinx文件:
  • 有时,Sphinx可以处理别名:

我不知道如何让sphinx知道模块别名,但这可能接近您想要的符号:

See the `fb.Thing <foobar.Thing>` class documentation for more details.
somefile.py

“”“
某些文档引用了外部记录的功能
:func:`numpy.searchsorted`或:func:`partial.update\u包装器`
"""
conf.py

#intersphinx设置
intersphinx_映射={'numpy':('https://docs.scipy.org/doc/numpy",无),,
“functools”:('https://docs.python.org/3.7/library/functools.html“,无)}

谢谢你的建议。使用相同数量的附加字符,实际上可以在没有intersphinx的情况下执行相同的操作:
`fb.thing`
(注意点而不是冒号)。但理想情况下,我试图避免docstring本身的这种额外混乱。Python知道
fb
foobar
的别名吗?所以我的意思是,是否有任何特殊属性,比如
\uuuuu模块\uuuuu
或类似属性,可以让Python内省代码看到/找到别名?如果不是,我认为甚至不可能用原生方式扩展Sphinx来创建内部别名表……用各种方式“告诉Python”这一事实是相当容易的。例如,您可以复制
sys.modules
中的条目,方法是说
sys.modules['fb']=sys.modules['foobar']
。任何代码都可以识别这种重复,只要代码注意检查在那里找到的模块的
\uuuuu name\uuuuuu
属性,因为
fb.\uuuu name\uuuuuu
将等于
'foobar'
。但是我假设,您不想将所有导入语句重写为那种样式,对吗?不,但这可以在
conf.py
中完成。我想这只需要斯芬克斯在运行的时候就可以了吧?