我在Github上有一个名为spike2py的Python包。我使用Sphinx和.rst文件准备了我的文档,这些文件托管在GitHub 这里。我能够成功地在本地运行
例如,以下是我本地呈现的参考指南的前一部分: 然而,当文档在
通过查看此处,我确认正在readthedocs上呈现的版本是我的文档的当前版本。
但是,当我尝试下载文档的PDF或HTML版本时,参考指南不包括文档字符串。 其他信息 根据readthedocs 文档,本地构建不应推送到GitHub;只需推送源文件。
make html
并获得所需的输出。也就是说,文档的参考指南部分包含了使用我在代码中包含的docstring自动生成的API,并使用autoclass
和autofunction
(reference_guide.rst)进行引用。例如,以下是我本地呈现的参考指南的前一部分: 然而,当文档在
readthedocs
上呈现时(请见此处),参考指南不包含提取的文档字符串,只有在.rst文件中找到的标题。
期望的行为
我期望在readthedocs上呈现的文档与本地呈现的文档相同。然而,这种情况并未发生。通过查看此处,我确认正在readthedocs上呈现的版本是我的文档的当前版本。
但是,当我尝试下载文档的PDF或HTML版本时,参考指南不包括文档字符串。 其他信息 根据readthedocs 文档,本地构建不应推送到GitHub;只需推送源文件。
这与这个问题有些相关,但我无法使建议的解决方案起作用。
更新
我按照Steve Piercy建议的解决方案做了,这解决了部分问题。我添加了一个docs/requirements.txt
文件和一个.readthedocs.yml
文件。
接下来我注意到构建正在使用Python 3.7.9。鉴于我使用的是Python >= 3.8的类型提示,我必须在.readthedocs.yml
文件中指定Python的版本。
然后我卡在了RTD构建告诉我找不到我的index.rst文件上。
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/application.py", line 348, in build
self.builder.build_update()
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 297, in build_update
self.build(to_build,
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 311, in build
updated_docnames = set(self.read())
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 421, in read
raise SphinxError('master file %s not found' %
sphinx.errors.SphinxError: master file /home/docs/checkouts/readthedocs.org/user_builds/spike2py/checkouts/latest/docs/index.rst not found
Sphinx error:
master file /home/docs/checkouts/readthedocs.org/user_builds/spike2py/checkouts/latest/docs/index.rst not found
但是我通过在我的.readthedocs.yml
中指定以下内容来解决了这个问题:
# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/source/conf.py
在此修复之后,文档构建时似乎没有出现错误,并包括以下内容:
generating indices... genindex py-modindexdone
highlighting module code... [ 20%] spike2py.channels
highlighting module code... [ 40%] spike2py.plot
highlighting module code... [ 60%] spike2py.read
highlighting module code... [ 80%] spike2py.sig_proc
highlighting module code... [100%] spike2py.trial
是的,文档字符串出现在 RTD 上了。
autodoc
在本地和GitHub上构建但在RTD上没有构建,那么很可能是因为RTD构建无法导入您的模块(我在该网站上经验不足以确定解决方案,但这是您应该搜索的逻辑 - 我希望更有经验的成员能够贡献他们对问题的分析。) - bad_coder