4

Recently I started using the sphinx_autodoc_typehints and the sphinx_autodoc_defaultargs extensions for Sphinx via my project's conf.py. As it seems are not default packages in the sphinx installation on readthedocs (over there sphinx is on v1.8.5). Because my build fails with an Extension error shown here:

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

I understand I somehow have to tell readthedocs to get sphinx_autodoc_typehints (and later sphinx_autodoc_defaultargs as well) from PyPI. Or is there a way I can install packages on readthedocs myself?

Since I use pbr for package management I use a requirements.txt that readthedocs knows of. I don't want to specify the sphinx extensions there because every user of my package would have to install them. Is there no other way of telling readthedocs which extensions to use?

MERose
  • 4,048
  • 7
  • 53
  • 79
  • Yes, and you can specify which version of any package include Sphinx by using a requirements file and specifying it in your project. See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html#pinning-dependencies – Steve Piercy Jul 13 '21 at 06:18

1 Answers1

2

Following the comment of Steve Piercy, I found a way to have two requiremens.txt. readthedocs' advanced settings (on the website) allow for one requirements.txt only.

readthedocs' preferred way are .readthedocs.yaml, which needs to live in the root folder. Following https://docs.readthedocs.io/en/stable/config-file/v2.html, this is how the file now looks like:

version: 2

sphinx:
  configuration: docs/conf.py

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

and the docs/requirements.txt looks like this:

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

In the advanced settings page I had to manually set the location of sphinx' conf.py, although it's a standard location. Without this setting my build would still fail.

MERose
  • 4,048
  • 7
  • 53
  • 79