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. 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 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

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}
 95
 96html_context = {
 97   "default_mode": "dark"
 98}
 99
100numfig = True
101math_numfig = True
102math_number_all = True
103
104notfound_urls_prefix = "/optrace/"
105
106# lazy load equations
107# improves loading speed of details/ pages significantly
108mathjax3_config = {
109    'loader': {'load': ['ui/lazy']},
110    'options': {
111        'lazyMargin': '400px',
112        'lazyAlwaysTypeset': None,
113    },
114}
115
116# links to libraries
117intersphinx_mapping = {'python': ('http://docs.python.org/3', None),
118                       'coverage': ('https://coverage.readthedocs.io/en/latest', None),
119                       'numpy': ('http://numpy.org/doc/stable', None),
120                       'pytest': ('https://docs.pytest.org/en/stable', None),
121                       'scipy': ('http://docs.scipy.org/doc/scipy/', None),
122                       'traits': ('https://docs.enthought.com/traits/', None),
123                       'matplotlib': ('http://matplotlib.org/stable', None),
124                       'mayavi': ('https://docs.enthought.com/mayavi/mayavi', None)}
125
126autodoc_default_options = {
127	'members': True,
128    'undoc-members': True,
129    'special-members' : '__call__, __eq__, __ne__',
130    'exclude-members': '__weakref__'
131}
132
133autodoc_member_order = 'groupwise'
134
135# move docstring from __init__ to class
136autoclass_content = "init"
137
138# move typehints from header to description
139autodoc_typehints = "description"
140
141# settings for sitemap generation
142sitemap_locales = [None]
143sitemap_url_scheme = "{link}"
144sitemap_excludes = [
145    "development/notes.html",
146    "development/changelog.html",
147    "development/packaging.html",
148    "development/documentation.html",
149    "development/testing.html",
150    "development/index.html",
151    "search.html",
152    "impressum.html",
153    "genindex.html",
154    "py-modindex.html",
155]
156
157# -- Misc Options -------------------------------------------------
158
159# ignore links that seemingly only work in a browser and not in automated tests
160linkcheck_ignore = [
161    'https://doi.org/10.1002/9783527648962.app1',
162    'https://www.publicdomainpictures.net/en/view-image.php',
163    'https://www.pexels.com/photo/sliced-fruits-on-tray-1132047/',
164    'https://www.pexels.com/photo/photo-of-people-standing-near-blackboard-3184393/',
165    'https://www.pexels.com/photo/green-island-in-the-middle-of-the-lake-during-daytime-724963/',
166    'https://www.pexels.com/photo/green-2-seat-sofa-1918291/',
167    'https://www.pexels.com/photo/documents-on-wooden-surface-95916/',
168    'https://www.pexels.com/photo/cars-on-street-during-night-time-3158562/',
169    'https://stackoverflow.com/questions/40065321/how-to-include-git-dependencies-in-setup-py-for-pip-installation',
170    'https://www.edmundoptics.com/knowledge-center/tech-tools/focal-length/',
171    'https://doi.org/10.1080/713818864',
172    'https://doi.org/10.1167/8.2.13',
173    'https://doi.org/10.1080/10867651.1997.10487479',
174    'https://stackoverflow.com/questions/68073819/pypi-install-requires-direct-links',
175    'https://eyewiki.org/Lens_Material_Properties',
176]
177
178linkcheck_timeout = 15
179linkcheck_workers = 3
180linkcheck_rate_limit_timeout = 15
181
182# only check doctest blocks
183doctest_test_doctest_blocks = ""
184