如何设置阅读文档,使Sphinx autodoc选项起作用?

问题描述 投票:4回答:1

我的项目未使用autodoc构建。我遇到了this frequently asked question about my project not building in autodoc。但是,某些依赖项包括无法在Build Docs服务器上执行的C代码。因此,我阅读了本blog explaining that I should use mock中的方法。这与stackoverflow问题“如何从x导入工作中模拟出来”有关。

在“阅读文档”的管理页面的“高级设置”部分中,有一个选项可以使用virtualenv(我已选中该选项,然后请求了指向我的项目根目录的路径指向requirements.txt。

项目目录的结构为:

GatherNews/
    requirements.txt

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

/ var / build / user_builds / gathernews / checkouts / latest / docs / api / grss.rst:10:警告:autodoc:无法从模块u'gathernews.gRSS'导入类u'CaptureFeeds';引发了以下异常:

回溯(最近通话):

file“ /home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/sphinx/ext/autodoc.py”,行335,在import_object < [导入((self.modname)

文件“ /home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/gathernews/

init

.py”,第1行,在导入gRSS文件“ /home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/gathernews/gRSS.py”,第38行,在导入feedparser中

[导入错误:没有名为feedparser /var/build/user_builds/gathernews/checkouts/latest/docs/_themes/README.rst ::的模块:警告:文档未包含在任何toctree中

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

python git documentation mocking documentation-generation
1个回答
4
投票
我创建了一个https://github.com/Bonza-Times/GatherNews的fork,并为此设置了一个ReadTheDocs构建。唯一的问题似乎是您使用了错误的requirements.txt路径。它说

从项目根目录开始的路径。

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

由于已检查Use virtualenv,ReadTheDocs应该自动确保确保virtualenv的站点程序包在sys.pathsphinx-build脚本中可用。

我看不到需要模拟模块,因为feedparser对C库没有任何硬性依赖。它

can是针对libxml2构建的,但不是必须的。

通过固定requirements.txt的路径,我能够成功完成构建。

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

“高级设置”“>

© www.soinside.com 2019 - 2024. All rights reserved.