7.2. Documentation

7.2.1. Overview

The documentation should contain information about the project, its usage as well as implementation and programming details. All 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.

7.2.2. Workflow

The gen_docs.yml action compiles the documentation and publishes it in the gh-pages branch. In the future, this content will be published on a webpage.

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 and a source file toctree.

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 self-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 looking 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

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]
 47
 48# Add any paths that contain templates here, relative to this directory.
 49templates_path = ['_templates']
 50
 51# List of patterns, relative to source directory, that match files and
 52# directories to ignore when looking for source files.
 53# This pattern also affects html_static_path and html_extra_path.
 54exclude_patterns = []
 55
 56bibtex_bibfiles = ['bib.bib']
 57bibtex_default_style = 'unsrt'
 58
 59# -- Options for HTML output -------------------------------------------------
 60
 61# The theme to use for HTML and HTML Help pages.  See the documentation for
 62# a list of builtin themes.
 63html_theme = "shibuya"
 64
 65# Add any paths that contain custom static files (such as style sheets) here,
 66# relative to this directory. They are copied after the builtin static files,
 67# so a file named "default.css" will overwrite the builtin "default.css".
 68html_static_path = ['_static']
 69html_css_files = ['css/custom.css']
 70html_baseurl = metadata["documentation"]
 71
 72html_theme_options = {
 73    "nav_links": [
 74        {
 75            "title": "Examples",
 76            "url": "./examples"
 77        },
 78        {
 79            "title": "Installation",
 80            "url": "./installation"
 81        },
 82        {
 83            "title": "User Guide",
 84            "url": "./usage/index"
 85        },
 86        {
 87            "title": "GitHub Repo",
 88            "url": "https://github.com/drocheam/optrace"
 89        }
 90    ],
 91    "accent_color": "cyan",
 92    "color_mode": "dark",
 93}
 94
 95html_context = {
 96   "default_mode": "dark"
 97}
 98
 99numfig = True
100math_numfig = True
101math_number_all = True
102
103# lazy load equations
104# improves loading speed of details/ pages significantly
105mathjax3_config = {
106    'loader': {'load': ['ui/lazy']},
107    'options': {
108        'lazyMargin': '400px',
109        'lazyAlwaysTypeset': None,
110    },
111}
112
113# links to libraries
114intersphinx_mapping = {'python': ('http://docs.python.org/3', None),
115                       'coverage': ('https://coverage.readthedocs.io/en/latest', None),
116                       'numpy': ('http://numpy.org/doc/stable', None),
117                       'pytest': ('https://docs.pytest.org/en/stable', None),
118                       'scipy': ('http://docs.scipy.org/doc/scipy/', None),
119                       'traits': ('https://docs.enthought.com/traits/', None),
120                       'matplotlib': ('http://matplotlib.org/stable', None),
121                       'mayavi': ('https://docs.enthought.com/mayavi/mayavi', None)}
122
123autodoc_default_options = {
124	'members': True,
125    'undoc-members': True,
126    'special-members' : '__call__, __eq__, __ne__',
127    'exclude-members': '__weakref__'
128}
129
130autodoc_member_order = 'groupwise'
131
132# move docstring from __init__ to class
133autoclass_content = "init"
134
135# move typehints from header to description
136autodoc_typehints = "description"
137
138# settings for sitemap generation
139sitemap_locales = [None]
140sitemap_url_scheme = "{link}"
141sitemap_excludes = [
142    "development/notes.html",
143    "development/changelog.html",
144    "development/packaging.html",
145    "development/documentation.html",
146    "development/testing.html",
147    "development/index.html",
148    "search.html",
149    "impressum.html",
150    "genindex.html",
151    "py-modindex.html",
152]
153
154# -- Misc Options -------------------------------------------------
155
156# ignore links that seemingly only work in a browser and not in automated tests
157linkcheck_ignore = [
158    'https://doi.org/10.1002/9783527648962.app1',
159    'https://www.publicdomainpictures.net/en/view-image.php',
160    'https://www.pexels.com/photo/sliced-fruits-on-tray-1132047/',
161    'https://www.pexels.com/photo/photo-of-people-standing-near-blackboard-3184393/',
162    'https://www.pexels.com/photo/green-island-in-the-middle-of-the-lake-during-daytime-724963/',
163    'https://www.pexels.com/photo/green-2-seat-sofa-1918291/',
164    'https://www.pexels.com/photo/documents-on-wooden-surface-95916/',
165    'https://www.pexels.com/photo/cars-on-street-during-night-time-3158562/',
166    'https://stackoverflow.com/questions/40065321/how-to-include-git-dependencies-in-setup-py-for-pip-installation',
167    'https://www.edmundoptics.com/knowledge-center/tech-tools/focal-length/',
168    'https://doi.org/10.1080/713818864',
169    'https://doi.org/10.1167/8.2.13',
170    'https://doi.org/10.1080/10867651.1997.10487479',
171    'https://stackoverflow.com/questions/68073819/pypi-install-requires-direct-links',
172    'https://eyewiki.org/Lens_Material_Properties',
173]
174
175linkcheck_timeout = 15
176linkcheck_workers = 3
177linkcheck_rate_limit_timeout = 15
178
179# only check doctest blocks
180doctest_test_doctest_blocks = ""
181