Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReadTheDocs not parsing docstrings in Python modules (Sphinx)

I have open-sourced some of my code, but the documentation won't build properly on ReadTheDocs despite working as expected with the Makefile created by sphinx-quickstart and make html locally. Can anyone please advise as to what I'm doing wrong with the RTD integration?

I have read about possibly building the module in a virtualenv with the RTD advanced settings but that doesn't work because I have scipy as a requirement and builds fail due to no BLAS library being available (it is also an unnecessarily long task for every build of docs).

sphinx.ext.autodoc and sphinx.ext.napoleon (for Google-style docstrings) are both included. Locally I just ran dev-scripts/api-docs.sh once which created docs/source/bnol.rst and docs/source/modules.rst. Then the standard Makefile (ignored in the git repo) is used to build docs as expected.

  • GitHub repository with package in /bnol/
  • Sphinx conf.py
  • RTD-hosted docs not built properly

EDIT: I found this FAQ detailing the build process on RTD and used the same process with sphinx-build locally and it works as expected. I am trawling RTD logs for errors but nothing of note just yet.

like image 390
Arran Schlosberg Avatar asked Apr 17 '16 14:04

Arran Schlosberg


People also ask

How do you access docstrings in Python?

Docstrings are accessible from the doc attribute (__doc__) for any of the Python objects and also with the built-in help() function. An object's docstring is defined by including a string constant as the first statement in the object's definition.

Where do Module docstrings go?

Module docstrings are placed at the top of the file even before any imports. Module docstrings should include the following: A brief description of the module and its purpose. A list of any classes, exception, functions, and any other objects exported by the module.


1 Answers

Usage of Sphinx's autodoc to create documentation from docstring comments requires that Python files be loaded and hence all of the modules that they import will so too be imported. ReadTheDocs will build required modules which, particularly in the case of numpy and scipy, may fail.

I corrected the problem by removing the modules from setup.py and instead listing them in a pip requirements file ./requirements.txt in the root of the package for use in actual package installation. A dummy (empty) requirements file was then placed in ./docs/source/ and ReadTheDocs configuration was pointed there (it appeared to automatically load ./requirements.txt even if not specified, hence the need for the dummy).

This still leaves the problem of importing modules which was fixed with mock as seen in my ./docs/source/conf.py file and detailed at: http://blog.rtwilson.com/how-to-make-your-sphinx-documentation-compile-with-readthedocs-when-youre-using-numpy-and-scipy/

A full list of changes can be seen in the commit that solved the problem.

like image 144
Arran Schlosberg Avatar answered Nov 15 '22 09:11

Arran Schlosberg