Install sphinx.
Create a
docs/
directory in your project's directory.In a terminal, go to the
docs/
directory and runsphinx-quickstart
to generate aconf.py
andindex.rst
, make sure you:- say yes to
separate source and build directories
- keep the source file suffix as
.rst
- say yes to autodoc:
automatically insert docstrings from modules
- say yes to doctest
- say yes to
Now you can generate html by running
make html
to check the build succeeded.To create a run configuration for this in PyCharm, add a new run configuration from
Python Docs > Sphinx Task
, set the directory that containsconf.py
as input (probablydocs/source/
, and select the directory containing generated html files (probablydocs/build/html
) as output.Uncomment the following lines in
docs/source/conf.py
(probably lines 15-17):import os import sys sys.path.insert(0, os.path.abspath('.'))
and change the last line to:
sys.path.insert(0, os.path.abspath('../..'))
Add each package to the table of contents, the toctree in
index.rst
. In this example that would be thenoodles
and thespaghetti
packages (subpackages will be automatically included):.. toctree:: :maxdepth: 2 noodles spaghetti
Make sure each package and subpackage you want to have in the documentation contains a
__init__.py
file, including thesrc
directory if you have it.
- After changing/adding files/packages: Run in a terminal in your project's top-level directory
sphinx-apidoc -M -T -E -f -o docs/source .
to generate a.rst
file for each package. You can find what each option does in the apidocdocumentation. Do this every time you change something in your code/docstrings. - After changing documentation in the code: Run the run configuration or
make html
to create the html.
For publishing the documentation on GitHub Pages, see for example https://daler.github.io/sphinxdoc-test/includeme.html#set-up-separate-docs-repository.