Skip to content

Commit

Permalink
docs: run autodoc as part of normal sphinx build
Browse files Browse the repository at this point in the history
Problem: when the documentation is built by ReadTheDocs with Sphinx,
they (RTD) do not run autodoc first, resulting in a mostly empty doc
site.

Solution: follow the workaround prescribed in
readthedocs/readthedocs.org#1139 and add code
to the conf.py to run autodoc as part of the normal sphinx build process
  • Loading branch information
SteVwonder committed May 18, 2021
1 parent 8043d3d commit 4e23e54
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys

import sphinx_rtd_theme
from sphinx.ext.apidoc import main

needs_sphinx = '1.6'

Expand Down Expand Up @@ -34,15 +35,31 @@
autodoc_typehints = "description"


src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))
script_dir = os.path.normpath(os.path.dirname(__file__))
src_dir = os.path.abspath(os.path.join(script_dir, '../src'))

print(src_dir + "/")

sys.path.insert(0, src_dir)

import psi


intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
}

# -- Setup for Sphinx API Docs -----------------------------------------------

# Workaround since sphinx does not automatically run apidoc before a build
# Copied from https://github.com/readthedocs/readthedocs.org/issues/1139

# run api doc
def run_apidoc(_):
output_path = os.path.join(script_dir, '.generated')
print(f"OUTPUT PATH = {output_path}")
#exclusions = [os.path.join(src_dir, 'setup.py'),]
main(['-f', '-o', output_path, src_dir])

# launch setup
def setup(app):
app.connect('builder-inited', run_apidoc)

0 comments on commit 4e23e54

Please sign in to comment.