python - 我如何设置 Read the Docs 以便 Sphinx autodoc 选项起作用?

标签 python git documentation mocking documentation-generation

我的项目不是使用 autodoc 构建的。我遇到了 this frequently asked question about my project not building in autodoc .但是,一些依赖项包括不会在构建文档服务器上执行的 c 代码。所以我阅读了这个 blog explaining that I should use mock 中的方法.这与 stackoverflow 问题“how-to-mock-so-that-from-x-import-works”有关。

在阅读文档的管理页面的高级设置部分,有一个使用 virtualenv 的选项,我检查了它,然后请求了我的项目根目录到 requirements.txt 的路径。

项目目录结构如下:

GatherNews/
    requirements.txt

当我使用 GatherNews/requirements.txt 作为路径时。我收到错误:

/var/build/user_builds/gathernews/checkouts/latest/docs/api/grss.rst:10: WARNING: autodoc: failed to import class u'CaptureFeeds' from module u'gathernews.gRSS'; the following exception was raised:

Traceback (most recent call last):

File "/home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 335, in import_object import(self.modname)

File "/home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/gathernews/init.py", line 1, in import gRSS

File "/home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/gathernews/gRSS.py", line 38, in import feedparser

ImportError: No module named feedparser /var/build/user_builds/gathernews/checkouts/latest/docs/_themes/README.rst:: WARNING: document isn't included in any toctree

我的问题是如何将它们联系在一起?具体来说,我是否使用了正确的 requirements.txt 路径来阅读文档以成功构建?如果我的 requirements.txt 路径是正确的,那么我如何包含模拟包以成功生成自动文档?

最佳答案

我创建了一个 https://github.com/Bonza-Times/GatherNews 的分支并为其构建了一组 ReadTheDocs。唯一的问题似乎是您使用了错误的 requirements.txt 路径。它说

Path from the root of your project.

因此不包括 GatherNews。只需使用 requirements.txt 作为路径,因为该文件位于 git 存储库的顶层。

因为你已经选中了 Use virtualenv,ReadTheDocs 应该自动确保 virtualenv 的站点包在 sys.path sphinx-build 脚本。

我没有看到任何模拟模块的需要,因为 feedparser 对 C 库没有任何硬依赖性。它可以针对 libxml2 构建,但并非必须如此。

通过修复 requirements.txt 的路径,我能够成功构建。

这些是我使用的“高级设置”,其余设置为默认值:

Advanced settings

关于python - 我如何设置 Read the Docs 以便 Sphinx autodoc 选项起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21811487/

相关文章:

git - 如何在 git-bash 中制作文本文件?

git - 无法使用 http/https 将 Git 推送到远程存储库

formatting - ":"、 "@"和 python 文档字符串中没有的区别

language-agnostic - 提高代码可读性

python - 在 python 中从多元 pdf 中采样

python - 是否遵循MVC的任何基于python的Web框架?

git - 如何重命名大量文件

Javadocs 链接到外部 javadoc

python - 如何在 Python 中的一个常规 Pandas DataFrame 中加入许多零散的时间序列

python - 如何检查浮点值是否在一定范围内并具有给定的小数位数?