交叉引用 Jupyter notebook 中 Sphinx 的 automodule 指令生成的 Python 函数

Cross reference a Python function generated by Sphinx's automodule directive from Jupyter notebook

使用 Sphinx's automodule 指令,我正在为我的模块中的所有函数从它们各自的文档字符串创建一个 API 文档。相应的 .rst 文件仅包含以下几行:

API Reference
=============
.. automodule:: pkg_name.module_name
   :members:
   :undoc-members:
   :show-inheritance:

我还使用 nbSphinx 将 Jupyter notebook 集成到文档中。

如何从 Jupyter notebook 中的 markdown 单元交叉引用由 automodule 指令创建的函数?

诚然它有点笨拙,但我就是这样做的:https://nbsphinx.readthedocs.io/en/0.8.2/markdown-cells.html#Links-to-Domain-Objects

换句话说:

如果您的 .rst 文件名为 api_reference.rst,您可以 link 像这样进入自动生成的函数文档:

[my_function()](api_reference.rst#pkg_name.module_name.my_function)

如果不知道#后面具体放什么,可以看函数文档自动生成的permalink。 重要的是您使用 .rst(即源文件的扩展名)而不是 .html(即生成的输出文件的扩展名)。