I have a Python package hosted on Github called spike2py. I have prepared my docs using Sphinx and .rst files. These files are hosted on GitHub here. I am able to successfully run make html
locally and obtain the desired output. That is, the Reference Guide part of the documentation contains the API automatically generated using the docstring I have included in my code, and referenced using calls to autoclass
and autofunction
(reference_guide.rst).
For example, here is what the first part of the Reference Guide looks like when I render it locally:
However, when the documentation is rendered on readthedocs
(see here), the Reference Guide does not contain the extracted doctrings; just the headers found in the .rst file.
Expected behaviour
I expected the docs rendered on readthedocs to be same as those rendered locally. However, this is not happening.
By looking here, I have confirmed that the version being presented on readthedocs in the current version of my documentation.
But when I try to download PDF or HTML versions of the documentation, the Reference Guide does not include the docstrings.
Other info
According to the readthedocs documentation, the local builds should not be pushed to GitHub; only the source files.
This is somewhat related to this issue, but I was not able to make the proposed solution work.
UPDATE
I followed the solution recommended by Steve Piercy and this solved part of the problem. I added a docs/requirements.txt
file as well as a .readthedocs.yml
file.
Next I noticed that the build was using Python 3.7.9. Given that I was using type hints from Python >= 3.8, I had to specify the version of Python in the .readthedocs.yml
file.
Then I was stuck with the RTD build telling me it can't find my index.rst file.
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/application.py", line 348, in build
self.builder.build_update()
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 297, in build_update
self.build(to_build,
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 311, in build
updated_docnames = set(self.read())
File "/home/docs/checkouts/readthedocs.org/user_builds/spike2py/envs/latest/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 421, in read
raise SphinxError('master file %s not found' %
sphinx.errors.SphinxError: master file /home/docs/checkouts/readthedocs.org/user_builds/spike2py/checkouts/latest/docs/index.rst not found
Sphinx error:
master file /home/docs/checkouts/readthedocs.org/user_builds/spike2py/checkouts/latest/docs/index.rst not found
But I then solved this by specifying the following in my .readthedocs.yml
:
# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/source/conf.py
After this fix, the docs are built with what appears to be no errors and includes the following:
generating indices... genindex py-modindexdone
highlighting module code... [ 20%] spike2py.channels
highlighting module code... [ 40%] spike2py.plot
highlighting module code... [ 60%] spike2py.read
highlighting module code... [ 80%] spike2py.sig_proc
highlighting module code... [100%] spike2py.trial
And yes, the doctrings appeared on RTD.
autodoc
is building locally and on GitHub but not on RTD chances are it's because the RTD build can't import your modules (I'm not experienced enough on that site to pinpoint a solution, but this is the logic you should search for - I hope a more experienced member can contribute their analyses of the problem.) – Sammysamoan