Sphinx in shortΒΆ
Brief view of the steps to set up Sphinx for your project:
Open a terminal and go to the project directory.
Launch sphinx-quickstart
$ sphinx-quickstart
Open
docs/source/conf.pyto make the following changes:Set the path to the code:
sys.path.insert(0, os.path.abspath('../..'))
Add napoleon to the extensions list 1:
extensions = [..., 'sphinx.ext.napoleon']
Import version from the project:
import <project name> version = <project name>.__version__ release = <project name>.__version__
Change the HTML theme:
html_theme = 'sphinx_rtd_theme'
Create your docs and add them to the toctree:
.. toctree:: :maxdepth: 2 intro tutorial ...
Generate API docs
Create the files to automatically load the docstrings and generate the corresponding docs:
$ sphinx-apidoc -f -o docs/source/pkg . test setup.pyAdd the
docs/source/pkg/modules.rstfile to a toctree.
Build your docs:
$ make html
- 1
The napoleon extension in needed to use Google or Numpy docstring. Skip this step if you are using reStructuredText format for the docstrings.