7.2. Documentation

7.2.1. Overview

The documentation contains information about the project, its usage as well as implementation and programming details. Everything should be presented as easily navigable webpage which includes figures, equations and code snippets.

To allow for a simple and up-to-date code reference, the process should be automatic, by generating it from typing hints and docstrings.

The online documentation is located here.

7.2.2. Workflow

The gen_docs.yml action compiles the documentation and publishes it in the gh-pages branch. The pages-build-deployment action deploys the documentation on the website.

Internally the workflow executes the docs environment for tox (see the tox file), which builds the documentation with the help of Sphinx. The steps also include an automatic generation of a changelog, source file toctree and sitemap.

7.2.3. Documentation Generation

The documentation is created with Sphinx, which uses reStructuredText as markup language. The html builder of Sphinx compiles a webpage including the written documentation, automatically generated code information, as well as indices for searching.

The following extensions are used:

doctest

automatic testing of documentation code examples

autodoc

automatic source code documentation generation

intersphinx

linking to the documentation of external packages

mathjax

LaTeX equations

sphinxcontrib.bibtex

bibliography management

Shibuya Sphinx Theme

A modern theme

Sphinx Sitemap

Generate sitemaps while building the documentation

Sphinx Mathjax Offline

Provides the mathjax js and font files without having to rely on an external CDN

sphinx-notfound-page

Fixes some issues with 404 pages

Additionally, a custom css (docs/source/_static/css/custom.css) adapts the formatting to our needs.

Documentation source files can be found under docs/source/ The Sphinx configuration can be found below.

Content of docs/source/conf.py

  1# Configuration file for the Sphinx documentation builder.
  2#
  3
  4# -- Path setup --------------------------------------------------------------
  5
  6# If extensions (or modules to document with autodoc) are in another directory,
  7# add these directories to sys.path here. If the directory is relative to the
  8# documentation root, use os.path.abspath to make it absolute, like shown here.
  9#
 10import os
 11import sys
 12import datetime
 13
 14sys.path.insert(0, os.path.abspath('..'))
 15sys.path.insert(0, os.path.abspath(os.path.join('..', '..')))
 16
 17
 18# -- Project information -----------------------------------------------------
 19
 20# load package information
 21metadata = {}
 22path = os.path.join("..", "..", "optrace", "metadata.py")
 23with open(path, "r") as f:
 24    exec(f.read(), metadata)
 25
 26# assign metadata
 27project = metadata["name"]
 28release = metadata["version"]
 29author = metadata["author"]
 30copyright = f"{datetime.date.today().year}, {author}"
 31language = "en"
 32
 33# -- General configuration ---------------------------------------------------
 34
 35# Add any Sphinx extension module names here, as strings. They can be
 36# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 37# ones.
 38extensions = [
 39        'sphinx.ext.autodoc',
 40        'sphinx.ext.intersphinx',
 41        'sphinx.ext.mathjax',
 42        'sphinx.ext.doctest',
 43        'sphinxcontrib.bibtex',
 44        'sphinx_sitemap',
 45        'sphinx-mathjax-offline',
 46        'notfound.extension',
 47]
 48
 49# Add any paths that contain templates here, relative to this directory.
 50templates_path = ['_templates']
 51
 52# List of patterns, relative to source directory, that match files and
 53# directories to ignore when looking for source files.
 54# This pattern also affects html_static_path and html_extra_path.
 55exclude_patterns = []
 56
 57bibtex_bibfiles = ['bib.bib']
 58bibtex_default_style = 'unsrt'
 59
 60# -- Options for HTML output -------------------------------------------------
 61
 62# The theme to use for HTML and HTML Help pages.  See the documentation for
 63# a list of builtin themes.
 64html_theme = "shibuya"
 65
 66# Add any paths that contain custom static files (such as style sheets) here,
 67# relative to this directory. They are copied after the builtin static files,
 68# so a file named "default.css" will overwrite the builtin "default.css".
 69html_static_path = ['_static']
 70html_css_files = ['css/custom.css']
 71html_baseurl = metadata["documentation"]
 72
 73html_theme_options = {
 74    "nav_links": [
 75        {
 76            "title": "Examples",
 77            "url": "./examples"
 78        },
 79        {
 80            "title": "Installation",
 81            "url": "./installation"
 82        },
 83        {
 84            "title": "User Guide",
 85            "url": "./usage/index"
 86        },
 87        {
 88            "title": "GitHub Repo",
 89            "url": "https://github.com/drocheam/optrace"
 90        }
 91    ],
 92    "accent_color": "cyan",
 93    "color_mode": "dark",
 94    "show_ai_links": False,  # uses icons from api.iconify
 95}
 96
 97html_context = {
 98   "default_mode": "dark"
 99}
100
101numfig = True
102math_numfig = True
103math_number_all = True
104
105notfound_urls_prefix = "/optrace/"
106
107# lazy load equations
108# improves loading speed of details/ pages significantly
109mathjax3_config = {
110    'loader': {'load': ['ui/lazy']},
111    'options': {
112        'lazyMargin': '400px',
113        'lazyAlwaysTypeset': None,
114    },
115}
116
117# links to libraries
118intersphinx_mapping = {'python': ('http://docs.python.org/3', None),
119                       'coverage': ('https://coverage.readthedocs.io/en/latest', None),
120                       'numpy': ('http://numpy.org/doc/stable', None),
121                       'pytest': ('https://docs.pytest.org/en/stable', None),
122                       'scipy': ('http://docs.scipy.org/doc/scipy/', None),
123                       'traits': ('https://docs.enthought.com/traits/', None),
124                       'matplotlib': ('http://matplotlib.org/stable', None),
125                       'pyvistaqt': ('https://qtdocs.pyvista.org/', None),
126                       'vtk': ('https://docs.vtk.org/en/latest', None),
127                       'pyvista': ('https://docs.pyvista.org', None)}
128
129autodoc_default_options = {
130	'members': True,
131    'undoc-members': True,
132    'special-members' : '__call__, __eq__, __ne__',
133    'exclude-members': '__weakref__'
134}
135
136autodoc_member_order = 'groupwise'
137
138# move docstring from __init__ to class
139autoclass_content = "init"
140
141# move typehints from header to description
142autodoc_typehints = "description"
143
144# settings for sitemap generation
145sitemap_locales = [None]
146sitemap_url_scheme = "{link}"
147sitemap_excludes = [
148    "development/notes.html",
149    "development/changelog.html",
150    "development/packaging.html",
151    "development/documentation.html",
152    "development/testing.html",
153    "development/index.html",
154    "search.html",
155    "impressum.html",
156    "genindex.html",
157    "py-modindex.html",
158]
159
160# -- Misc Options -------------------------------------------------
161
162# ignore links that seemingly only work in a browser and not in automated tests
163linkcheck_ignore = []
164
165linkcheck_timeout = 15
166linkcheck_workers = 3
167linkcheck_rate_limit_timeout = 15
168
169# only check doctest blocks
170doctest_test_doctest_blocks = ""
171