Skip to main content
 首页 » 编程设计

python之如何配置阅读文档以使用 sphinx-autodoc-annotation

2024年10月17日6kuangbin

我正在使用 sphinx-autodoc-annotation读取我的 Python 代码中的函数注释并使用它来生成适当的预期参数类型和返回类型。它在我的本地机器上运行良好,但我当然必须 pip install sphinx-autodoc-annotation。

我正在尝试使用 Read the Docs 生成相同的文档,但它给了我一个错误:

Could not import extension sphinx_autodoc_annotation (exception: No module named sphinx_autodoc_annotation) 

是否可以将阅读文档配置为与 sphinx-autodoc-annotation 一起使用,如果可以,我该如何让它工作?

请您参考如下方法:

我不喜欢通过 setup.py 打包一堆文档要求,所以我的建议是不要在 RTD 上使用 Install Project 选项。相反,我更喜欢将自定义 requirements.txt 放在我的 doc/ 文件夹中,并将 RTD 指向它:

将您在 setup.py 的 install_requires 和/或 requirements.txt 中的任何内容粘贴到此文件中。确保您正在使用的任何其他 sphinx 扩展也在其中。

这应该会处理您所有的依赖项。我推荐的其他有趣设置如下所示: