Writing Your Own Documentation

caproto provides some Sphinx and autodoc/autosummary-based helpers to aid users in the creation of their own (PVGroup-based) IOC documentation.

Sample conf.py

An HTML-centric conf.py may look like the following:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
import pathlib
import sys
from datetime import datetime

import sphinx_rtd_theme

import caproto
import caproto.docs

module_path = pathlib.Path(__file__).resolve().parents[2]
sys.path.insert(0, str(module_path))


project = 'YOUR_PROJECT'
author = 'YOUR_NAME'

copyright = f'{datetime.now().year}, {author}'

# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = ''

# -- General configuration ---------------------------------------------------
needs_sphinx = '3.2.1'

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.autosummary',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.mathjax',
    'sphinx.ext.viewcode',
    'sphinx.ext.githubpages',
    'sphinx.ext.intersphinx',
    'numpydoc',
    # 'doctr_versions_menu',
    'sphinx_rtd_theme',
]

templates_path = [caproto.docs.templates.PATH]

source_suffix = '.rst'
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
language = 'python'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# -- Options for HTML output -------------------------------------------------
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# html_theme_options = {}
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
# html_sidebars = {}

# -- Options for HTMLHelp output ---------------------------------------------
htmlhelp_basename = 'YOUR_PROJECT'

# -- Extension configuration -------------------------------------------------
autodoc_default_options = {
    'members': '',
    'member-order': 'bysource',
    'special-members': '',
    'undoc-members': False,
    'exclude-members': ''
}

intersphinx_mapping = {
    # 'ophyd': ('https://blueskyproject.io/ophyd', None),
    'python': ('https://docs.python.org/3', None),
    # 'numpy': ('https://docs.scipy.org/doc/numpy', None),
    'caproto': ('https://caproto.github.io/caproto/master', None),
}

autosummary_generate = True

# Duplicate attributes will be generated without this:
autoclass_content = 'init'

# Tons of warnings will be emitted without this:
numpydoc_show_class_members = False
autosummary_context = {
    **caproto.docs.autosummary_context,
    # The default assumes your repository root is one level up from conf.py.
    # If that is not accurate, uncomment and modify the following line:
    # 'project_root': '..',
}
html_context = {
    **autosummary_context,
    # 'css_files': [
    #     '_static/theme_overrides.css',  # override wide tables in RTD theme
    # ],
}


def setup(app):
    # Add your own setup here
    caproto.docs.setup(app)

Any and all of this can be customized. Users may also copy the templates out of caproto, though any improvements to these templates are always welcome in caproto itself.

Sample requirements-docs.txt

Building your documentation will require extra dependencies that aren’t necessary to run your package, most likely. The caproto developers recommend creating a separate requirements file that can be installed by way of pip or conda (i.e., pip install --requirement requirements-docs.txt or conda install --file requirements-docs.txt).

doctr
doctr-versions-menu
numpydoc
sphinx>=3.2.1
sphinx_rtd_theme>=0.5.0

doctr and doctr-versions-menu are useful if building documentation using continuous integration, but are unnecessary if you will only be building documentation locally.

Using autosummary

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
---------
PV Groups
---------

.. currentmodule:: package

.. autosummary::
    :toctree: ioc

   pkg.MyGroup


--------
Full API
--------

.. autosummary::
    :toctree: ioc

    pkg