微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

readthedocs 上的 Sphinx 扩展

如何解决readthedocs 上的 Sphinx 扩展

最近我开始通过我的项目的 conf.py 为 Sphinx 使用 sphinx_autodoc_typehintssphinx_autodoc_defaultargs 扩展。因为它似乎不是 readthedocs 上 sphinx 安装中的认包(那边 sphinx 在 v1.8.5 上)。因为我的构建失败并显示 Extension error here

Could not import extension sphinx_autodoc_typehints (exception: No module named 
'sphinx_autodoc_typehints')

我知道我必须以某种方式告诉 readthedocs 从 PyPI 获取 sphinx_autodoc_typehints(以及后来的 sphinx_autodoc_defaultargs)。 或者有什么方法可以让我自己在 readthedocs 上安装软件包?

因为我使用 pbr 进行包管理,所以我使用了 readthedocs 知道的 requirements.txt。我不想在那里指定 sphinx 扩展,因为我的包的每个用户都必须安装它们。 有没有其他方法可以告诉 readthedocs 使用哪些扩展?

解决方法

根据 Steve Piercy 的评论,我找到了一种方法来拥有两个 requiremens.txt。 readthedocs 的高级设置(在网站上)只允许一个 requirements.txt。

readthedocs 的首选方式是 .readthedocs.yaml,它需要位于根文件夹中。在 https://docs.readthedocs.io/en/stable/config-file/v2.html 之后,文件现在是这样的:

version: 2

sphinx:
  configuration: docs/conf.py

python:
  version: 3.7
  install:
    - requirements: requirements.txt
    - requirements: docs/requirements.txt

docs/requirements.txt 看起来像这样:

sphinx==3.4.3
sphinx_autodoc_typehints==1.12.0
sphinx_autodoc_defaultargs==0.1.2

在高级设置页面中,我必须手动设置 sphinx' conf.py 的位置,尽管它是标准位置。如果没有这个设置,我的构建仍然会失败。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。