Sphinx + Python on Github Pages / Jekyll

Related: Easier to use pdoc Python autodoc generator


Sphinx works great with Github Pages. Sphinx requires one-time setup as described below. The URL will be like https://scivision.github.io/pymap3d/.

Install Sphinx

Setup an environment for Sphinx otherwise it may downgrade other packages:

conda create -n sphinx

conda activate sphinx

Install Sphinx

pip install sphinx

setup docs

Use Sphinx Quickstart

sphinx-quickstart

Most defaults are fine, except:

autodoc: automatically insert docstrings from modules (y/n) [n]: y
mathjax: include math, rendered in the browser by MathJax (y/n) [n]: y
viewcode: include links to the source code of documented Python objects (y/n) [n]: y
githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: y

Add to .gitignore

doctrees/
.buildinfo

Edit docs/Makefile to include

SOURCEDIR     = .
BUILDDIR      = .

Create empty docs/.nojekyll or else Jekyll will reject all directories starting with _, breaking the Sphinx docs.

Edit docs/index.rst to have entries like

.. automodule:: pymap3d
  :members:

.. automodule:: pymap3d.vincenty
  :members:

Create docs/index.html containing only

<html>
<head>
<meta http-equiv="refresh" content="0; url=html/index.html" />
</head>
<body></body>
</html>

Add the docs directory to Git

git add docs/

In your Github repo Settings → Github Pages → Source: “master branch /docs folder”

git commit and git push. It takes a few seconds for Github Pages to deploy your HTML.