- Make sure that sphinx is installed.
$ pip install sphinx
- Since we will be using the Napoleon style of docstrings we need to install the
sphinx-napoleonpackage as well (https://sphinxcontrib-napoleon.readthedocs.io/en/latest/). Lets also install the ReadTheDocs theme so that our documentation page looks nice when created.
$ pip install sphinxcontrib-napoleon sphinx-rtd-theme
-
Copy the
exampledocdirectory somewhere into your repo andcdinto it. -
Now we are ready to initialize the documentation. Start by making a
docsdirectory in your repo. Then runsphinx-quickstart
$ mkdir docs
$ cd docs
$ sphinx-quickstart
Answer the questions when prompted on the terminal. You can answer n to the question: Separate source and build directories?.
This should create several files and directories in your current working directory, including conf.py.
$ ls
Makefile _build _static _templates conf.py index.rst make.bat
- Open
conf.pyin VScode or other editor. We'll need to uncomment the following lines in the "Path setup" section.
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
- Change the
os.path.abspath('.')part to point to the top level of your repo. In this example that would be...
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
-
Also change the
html_themevariable to "sphinx_rtd_theme", add the linemaster_doc='index'below your author name. Also add “sphinx.ext.autodoc” and "sphinx.ext.napoleon" to theextensionslist inconf.py. -
Now we are ready to build the documentation pages! Do this from the
docsdirectory.
$ make html
This will create a basic set of documentation pages in _build/html. Open up the index.html with your favorite browser.
- This page doesn't have any of the documentation from your docstrings yet, so lets add that. The content of these pages are controlled by the
.rst(reStructured text) files. Create a new.rstfile calledcorrelate.rst. The contents of this file should look like this:
.. _correlate:
Correlate
=========
.. automodule:: correlate
:members:
This will automatically parse correlate.py and look for your docstrings in order to turn them into a nicely-formatted web page.
-
Run
make htmlagain to update the docs. -
View your documentation by opening the file at
_build/html/index.html.
- Set up sphinx documentation for your project repo.
- Document at least one function in your package and make sure it builds in the sphinx documentation.
- (BONUS) Trade with another group and try to use one of their functions/classes/methods that they have documented using their sphinx documentation.