我正在使用 Sphinx 构建 Python 包的文档。
我有一个 API.rst 文件,其中列出了我的函数,如下所示: .. autofunction:: mymodule.foo.bar1
对于自动记录于此的不同函数例如,我可以
:func:`foo1`
在 foo2() 的文档字符串中放置: ,它将创建指向第一个函数的链接。
但是,如果我有第二个文件 API2.rst
,其中我自动文档化了一些其他函数,则相同的语法似乎无法找到不同页面之间的链接。甚至连See Also
功能也没有链接。
有没有办法跨页面指定和链接不同的功能?谢谢
示例
- 该存储库的文档可以在此处找到
- ,例如,在此文档字符串函数,在参数
peaks
下,我试图链接到另一个名为ecg_peaks()
的函数,该函数已记录此处
I am building a documentation of my Python package using Sphinx.
I have a API.rst
file, in which I list my functions as follows: .. autofunction:: mymodule.foo.bar1
For the different functions that are autodocumented form this page, I can put for instance:
:func:`foo1`
in the docstring of foo2()
and it will create a link to the first function.
However, if I have a second file API2.rst
, in which I autodoc some other functions, the same syntax doesn't seem to find the links across different pages. Even the See Also
functions are not linked.
Is there a way to specify and to link different functions across pages? Thanks
Example
- The repo's documentation can be found here
- For instance, in the docstring of this function, under the parameter
peaks
, I am trying to link to another function called ecg_peaks()
which is documented here
发布评论
评论(1)
为了总结其他评论者发现的内容,当Sphinx解决Python交叉引用时,它可以通过多种方式找到交叉引用目标。让我们举一个例子。
假设您有以下项目结构
绝对合格名称:您的文档中的任何地方
应该能够做出完全合格的参考
相对名称:在给定的模块中,您可以使用Python
直接对象名称。例如,从
来自foobar.py文件:
放松的合格名称:引用python对象时
您可以使用
。
字符来扩展目标的搜索空间。例如,来自foobar.py文件:另外,从Baz的类docString,in Baz.py:
放松方法的风险是狮身人面像会链接
第一件事发现,这可能不是目标
您期望。
最后,为防止这些问题公开,请使用
这是狮身人面像文档在此主题上说
To sum up what other commenters found, when Sphinx resolve Python cross-references, it can find the cross-reference targets in several ways. Let's get an example.
Say you have the following project structure
Absolute qualified name: Anywhere in your documentation you
should be able to make a fully qualified reference, like so
Relative name: In a given module, you can use the Python
object name directly. For instance, from within the
from foobar.py file:
Relaxed qualified name: When referencing a python object
you can use the
.
character to extend the search space for your target. As an example, from foobar.py file:Also, from the class docstring of Baz, in baz.py:
The risk with the relaxed method is that Sphinx will link
to the first thing it finds, which may of may not be the target
you expected.
Finally, to help prevent these issues go public, use the nitpick option
Here is what Sphinx documentation says on this topic