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.
/bnol/
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With