Skip to content

Commit 4e23e54

Browse files
committed
docs: run autodoc as part of normal sphinx build
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
1 parent 8043d3d commit 4e23e54

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

docs/conf.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55

66
import sphinx_rtd_theme
7+
from sphinx.ext.apidoc import main
78

89
needs_sphinx = '1.6'
910

@@ -34,15 +35,31 @@
3435
autodoc_typehints = "description"
3536

3637

37-
src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))
38+
script_dir = os.path.normpath(os.path.dirname(__file__))
39+
src_dir = os.path.abspath(os.path.join(script_dir, '../src'))
3840

3941
print(src_dir + "/")
4042

4143
sys.path.insert(0, src_dir)
4244

4345
import psi
4446

45-
4647
intersphinx_mapping = {
4748
'python': ('https://docs.python.org/3', None),
4849
}
50+
51+
# -- Setup for Sphinx API Docs -----------------------------------------------
52+
53+
# Workaround since sphinx does not automatically run apidoc before a build
54+
# Copied from https://github.com/readthedocs/readthedocs.org/issues/1139
55+
56+
# run api doc
57+
def run_apidoc(_):
58+
output_path = os.path.join(script_dir, '.generated')
59+
print(f"OUTPUT PATH = {output_path}")
60+
#exclusions = [os.path.join(src_dir, 'setup.py'),]
61+
main(['-f', '-o', output_path, src_dir])
62+
63+
# launch setup
64+
def setup(app):
65+
app.connect('builder-inited', run_apidoc)

0 commit comments

Comments
 (0)