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

问题描述

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

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

我还使用 nbSphinx 将 Jupyter 笔记本集成到文档中。

如何从 Jupyter 笔记本中的降价单元交叉引用由 automodule 指令创建的函数

解决方法

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

换句话说:

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

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

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