How to use Python 3.5 syntax in readthedocs combined with autodoc?

Viewed 1222

I would like to generate documentation (including automatically generated documentation with autodoc) for my project using readthedocs.org. However, my project uses Python 3.5 syntax (async and await) and it doesn't look like it can handle that. The build succeeds, although I get a lot of errors like this:

/home/docs/checkouts/readthedocs.org/user_builds/sparrow/checkouts/latest/docs/source/entity.rst:176: WARNING: autodoc: failed to import module 'sparrow.entity'; the following exception was raised:
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/sparrow/envs/latest/local/lib/python3.4/site-packages/sphinx/ext/autodoc.py", line 385, in import_object
    __import__(self.modname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/sparrow/checkouts/latest/sparrow/__init__.py", line 26, in <module>
    from .model import *
  File "/home/docs/checkouts/readthedocs.org/user_builds/sparrow/checkouts/latest/sparrow/model.py", line 37
    async def install(self):

Is there a way to fix this?

3 Answers

The other answers are a bit outdated as nowadays Readthedocs.org does support Python 3.5 and 3.6. To use it one has to configure the readthedocs.yml. Documentation about this can be found here: http://docs.readthedocs.io/en/latest/yaml-config.html.

A minimum example that would make Readthedocs.org use Python 3.5 is:

build:
    image: latest

python:
    version: 3.5

If you have any dependencies, this can be handled via a requirements.txt file or via setup.py. For example if you want to use the setup.py you simply tell Readthedocs.org to install your package:

build:
    image: latest

python:
    version: 3.5
    setup_py_install: true
Related