earthobservations / wetterdienst

Open weather data for humans.
https://wetterdienst.readthedocs.io/
MIT License
349 stars 54 forks source link

Make Sphinx autodoc work #156

Closed amotl closed 3 years ago

amotl commented 3 years ago

We found at https://github.com/earthobservations/wetterdienst/pull/153#issuecomment-692554115 that sphinx.ext.autodoc does not work on RTD yet, see Module library > API.

From the past, I know this is mostly a matter of getting the package itself installed properly into the Python environment where Sphinx will be building the documentation. When doing that, there's usually no way around also installing all its dependencies, which occasionally has problems within (restricted) CI environments.

amotl commented 3 years ago

I've tried to follow the guidelines at https://github.com/readthedocs/readthedocs.org/issues/4912#issuecomment-469023043 and also had a look at https://github.com/python-poetry/poetry/issues/754.

amotl commented 3 years ago

Investigation

TLDR; There might be an OOM issue when installing the project and its dependencies, which is required for a Autodoc environment to work out of the box. Apparently, there is also Sphinx AutoAPI, which does not have these requirements.

Details

There's a comment by @stsewd at https://github.com/readthedocs/readthedocs.org/issues/5847#issuecomment-505960920:

So, the autodoc feature of sphinx requires the project to be installed to extract the docs (because it actually executes the code). Autoapi extracts the docs in a static way (no need to run the code). So, when using autoapi, you can skip the dependencies installation for the project.

After @tlvu commented at https://github.com/readthedocs/readthedocs.org/issues/5847#issuecomment-519185831:

I guess I am not the only project with OOM problem because of the awsome sphinx autodoc feature. I solved my issue by mocking import (using autodoc_mock_imports in Sphinx's conf.py file, see my PR https://github.com/Ouranosinc/raven/pull/167) of all the 3rd party dependencies so they do not have to be installed for real and by adding my own sources into the sys.path for autodoc to parse for docstrings and auto generate the doc. I basically work-around the requirement to install my project and all its dependencies, resulting in less memory usage and faster build.

You might want to document this somewhere on ReadTheDocs docs so other users using sphinx autodoc will benefit and prevent other similar OOM support call in the future.

Also, @humitos chimed in at https://github.com/readthedocs/readthedocs.org/issues/5847#issuecomment-519198831:

On the other hand, we recommend to use autoapi if what you want is to auto document the modules. It's static and does not need to install anything to get the modules documentation 😉

amotl commented 3 years ago

However, in our case https://readthedocs.org/projects/wetterdienst/builds/ currently does not show any build errors at all, right?

amotl commented 3 years ago

When investigating the latest build at https://readthedocs.org/projects/wetterdienst/builds/11887538/ more thoroughly, these things can be observed:

amotl commented 3 years ago

I've tried to reproduce this on my machine by using a fresh Poetry environment for this project after wiping the old one using poetry env remove wetterdienst-EkOFQaO8-py3.8.

Then, I tried to go for the module mocking thing using autodoc_mock_imports, see also FAQ: I get import errors on libraries that depend on C modules.

After some complaints leading to f71ed0ea and 34433d93, things started to work. Enjoy https://wetterdienst.readthedocs.io/en/latest/pages/library/api.html.