sphinx超链接到在别名下导入的Python模块的成员
我维护了一个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
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
中完成。我想这只需要斯芬克斯在运行的时候就可以了吧?