Auto-generating the project API documentation
Auto-generating the project API documentation
Sphinx comes with another handy tool (sphinx-apidoc) which can be used
to automatically generate the API documentation for all source or src
modules of the project (assuming you have already been following some
best practices when it comes
to documenting your code).
The following steps demonstrate how to make use of this handy feature.
Open the
conf.pyfile in an editor. At the top of the file, assign a system path for locating the project modules directory by including the following line of code:sys.path.insert(0, os.path.abspath(<relative_path_to_source_modules>))
Run sphinx automatic API documentation to automatically generate an .rst file for each module located in the
srcfolder. This also generates amodules.rstfile containing a list of all thesrcmodules.-fforces override of any previously written .rst files with the same name.sphinx-apidoc -f -o source <relative_path_to_source_modules>
Open the
modules.rstfile and change the title to ‘API documentation’ or another title, as desired:
Then save the file.
Add a cross-reference to the
modules.rstfile in the toctree in theindex.rstfile:.. toctree:: :maxdepth: 5 :caption: My contents are better than your contents: mynewsection modules
Update the html pages with any changes (
make html):
Edit the text within each .rst module by adding directives to alter their output/behaviour. Some examples here.