Skip to content

Commit f8df05f

Browse files
committed
Automate building RST files for ReadTheDocs
Build the `.rst` files required to generate the API docs in ReadTheDocs. Although these files can be generated through a CLI flag, they are not built automatically during RTD generation. As inspired by this comment (readthedocs/readthedocs.org#1139 (comment)), add configuration steps to build the files automatically. This build avoids the need to commit the RST files to the repo.
1 parent dc312db commit f8df05f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/conf.py

+29
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,32 @@
206206
napoleon_use_ivar = True
207207
napoleon_use_param = True
208208
napoleon_use_rtype = True
209+
210+
211+
# automate building API .rst files, necessary for ReadTheDocs, as inspired by:
212+
# https://github.com/readthedocs/readthedocs.org/issues/1139#issuecomment-398083449
213+
def run_apidoc(_):
214+
ignore_paths = []
215+
216+
argv = [
217+
"-f",
218+
"-T",
219+
"-e",
220+
"-M",
221+
"-o", ".",
222+
".."
223+
] + ignore_paths
224+
225+
try:
226+
# Sphinx >= 1.7
227+
from sphinx.ext import apidoc
228+
apidoc.main(argv)
229+
except ImportError:
230+
# Sphinx < 1.7
231+
from sphinx import apidoc
232+
argv.insert(0, apidoc.__file__)
233+
apidoc.main(argv)
234+
235+
236+
def setup(app):
237+
app.connect('builder-inited', run_apidoc)

0 commit comments

Comments
 (0)