如何设置“读取文档”以便Sphinx autodoc选项正常工作?

2024-10-01 19:29:51 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

项目目录的结构如下:

GatherNews/
    requirements.txt

当我使用“GatherNews”时/要求.txt“就像这条路。我得到了一个错误:

/var/build/user_构建/gathernews/checkouts/latest/docs/api/总重:10:警告:autodoc:无法从模块u导入类u“CaptureFeeds”gathernews.gRSS网站引发了以下异常:“”

回溯(最近一次呼叫):

文件“/主页/文档/签出/阅读docs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/现场包/狮身人面像/分机/自动文档.py“,第335行,在import_objectimport(self.modname)在

文件“/主页/文档/签出/阅读docs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site packages/gathernews/init.py”,第1行,在import gRSS中

文件“/主页/文档/签出/阅读docs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/网站包/gathernews/gRSS.py公司“,第38行,在import feedparser中

ImportError:没有名为feedparser/var/build/user_builds/gathernews/checkouts/latest/docs/\u themes的模块/自述文件.rst●警告:文档不包含在任何目录树中

我的问题是如何把这些联系起来?具体来说,我是否使用正确的路径要求.txt为了成功地读取文档?如果我的路要求.txt是正确的,那么如何包含模拟包来成功生成autodocs?在


Tags: 文件项目文档orgimporttxtdocs主页
1条回答
网友
1楼 · 发布于 2024-10-01 19:29:51

我为它创建了一个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到{}脚本中可用。在

我认为没有必要模仿模块,因为feedparser对C库没有任何硬依赖关系。它可以针对libxml2构建,但不是必须的。在

修复了requirements.txt的路径后,我可以成功地构建。在

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

Advanced settings

相关问题 更多 >

    热门问题