| 1 | #!/usr/bin/env python3 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # |
| 4 | # labgrid documentation build configuration file, created by |
| 5 | # sphinx-quickstart on Mon Feb 20 10:00:00 2017. |
| 6 | # |
| 7 | # This file is execfile()d with the current directory set to its |
| 8 | # containing dir. |
| 9 | # |
| 10 | # Note that not all possible configuration values are present in this |
| 11 | # autogenerated file. |
| 12 | # |
| 13 | # All configuration values have a default; values that are commented out |
| 14 | # serve to show the default. |
| 15 | |
| 16 | # If extensions (or modules to document with autodoc) are in another directory, |
| 17 | # add these directories to sys.path here. If the directory is relative to the |
| 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
| 19 | # |
| 20 | import os |
| 21 | import sys |
| 22 | sys.path.insert(0, os.path.abspath('..')) |
| 23 | |
| 24 | from importlib import metadata |
| 25 | |
| 26 | # Import read_the_docs theme |
| 27 | import sphinx_rtd_theme |
| 28 | |
| 29 | # -- General configuration ------------------------------------------------ |
| 30 | |
| 31 | # If your documentation needs a minimal Sphinx version, state it here. |
| 32 | # |
| 33 | # needs_sphinx = '1.0' |
| 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. |
| 38 | extensions = ['sphinx.ext.autodoc', |
| 39 | 'sphinx.ext.doctest', |
| 40 | 'sphinx.ext.napoleon', |
| 41 | 'sphinx.ext.coverage', |
| 42 | 'sphinx.ext.viewcode', |
| 43 | 'sphinxcontrib.autoprogram', |
| 44 | 'sphinx.ext.autosectionlabel', |
| 45 | 'sphinx_rtd_theme'] |
| 46 | |
| 47 | # Add any paths that contain templates here, relative to this directory. |
| 48 | templates_path = ['.templates'] |
| 49 | |
| 50 | # The suffix(es) of source filenames. |
| 51 | # You can specify multiple suffix as a list of string: |
| 52 | # |
| 53 | # source_suffix = ['.rst', '.md'] |
| 54 | source_suffix = '.rst' |
| 55 | |
| 56 | # The master toctree document. |
| 57 | master_doc = 'index' |
| 58 | |
| 59 | # General information about the project. |
| 60 | project = 'labgrid' |
| 61 | copyright = '2016-2025 Pengutronix, Jan Luebbe and Rouven Czerwinski' |
| 62 | author = 'Jan Luebbe, Rouven Czerwinski' |
| 63 | |
| 64 | # The version info for the project you're documenting, acts as replacement for |
| 65 | # |version| and |release|, also used in various other places throughout the |
| 66 | # built documents. |
| 67 | # |
| 68 | # The full version, including alpha/beta/rc tags. |
| 69 | release = metadata.version('labgrid') |
| 70 | # The short X.Y version. |
| 71 | version = '.'.join(release.split('.')[:2]) |
| 72 | |
| 73 | # The language for content autogenerated by Sphinx. Refer to documentation |
| 74 | # for a list of supported languages. |
| 75 | # |
| 76 | # This is also used if you do content translation via gettext catalogs. |
| 77 | # Usually you set "language" from the command line for these cases. |
| 78 | language = 'en' |
| 79 | |
| 80 | # List of patterns, relative to source directory, that match files and |
| 81 | # directories to ignore when looking for source files. |
| 82 | # This patterns also effect to html_static_path and html_extra_path |
| 83 | exclude_patterns = ['.build', 'Thumbs.db', '.DS_Store', 'RELEASE.rst'] |
| 84 | |
| 85 | # The name of the Pygments (syntax highlighting) style to use. |
| 86 | pygments_style = 'sphinx' |
| 87 | |
| 88 | # If true, `todo` and `todoList` produce output, else they produce nothing. |
| 89 | todo_include_todos = False |
| 90 | |
| 91 | |
| 92 | # -- Options for HTML output ---------------------------------------------- |
| 93 | |
| 94 | # The theme to use for HTML and HTML Help pages. See the documentation for |
| 95 | # a list of builtin themes. |
| 96 | # |
| 97 | html_theme = 'sphinx_rtd_theme' |
| 98 | |
| 99 | # Theme options are theme-specific and customize the look and feel of a theme |
| 100 | # further. For a list of options available for each theme, see the |
| 101 | # documentation. |
| 102 | # |
| 103 | # html_theme_options = {} |
| 104 | |
| 105 | # Add any paths that contain custom static files (such as style sheets) here, |
| 106 | # relative to this directory. They are copied after the builtin static files, |
| 107 | # so a file named "default.css" will overwrite the builtin "default.css". |
| 108 | html_static_path = [] |
| 109 | |
| 110 | # The name of an image file (relative to this directory) to place at the top |
| 111 | # of the sidebar. |
| 112 | html_logo = 'images/labgrid_logo_outline.svg' |
| 113 | |
| 114 | # The name of an image file (within the static path) to use as favicon of the |
| 115 | # docs. |
| 116 | html_favicon = 'images/favicon.png' |
| 117 | |
| 118 | |
| 119 | # -- Options for HTMLHelp output ------------------------------------------ |
| 120 | |
| 121 | # Output file base name for HTML help builder. |
| 122 | htmlhelp_basename = 'labgriddoc' |
| 123 | |
| 124 | |
| 125 | # -- Options for LaTeX output --------------------------------------------- |
| 126 | |
| 127 | latex_elements = { |
| 128 | # The paper size ('letterpaper' or 'a4paper'). |
| 129 | # |
| 130 | # 'papersize': 'letterpaper', |
| 131 | |
| 132 | # The font size ('10pt', '11pt' or '12pt'). |
| 133 | # |
| 134 | # 'pointsize': '10pt', |
| 135 | |
| 136 | # Additional stuff for the LaTeX preamble. |
| 137 | # |
| 138 | # 'preamble': '', |
| 139 | |
| 140 | # Latex figure (float) alignment |
| 141 | # |
| 142 | # 'figure_align': 'htbp', |
| 143 | } |
| 144 | |
| 145 | # Grouping the document tree into LaTeX files. List of tuples |
| 146 | # (source start file, target name, title, |
| 147 | # author, documentclass [howto, manual, or own class]). |
| 148 | latex_documents = [ |
| 149 | (master_doc, 'labgrid.tex', 'labgrid Documentation', |
| 150 | 'Jan Luebbe, Rouven Czerwinski', 'manual'), |
| 151 | ] |
| 152 | |
| 153 | |
| 154 | # -- Options for manual page output --------------------------------------- |
| 155 | |
| 156 | # One entry per manual page. List of tuples |
| 157 | # (source start file, name, description, authors, manual section). |
| 158 | man_pages = [ |
| 159 | (master_doc, 'labgrid', 'labgrid Documentation', |
| 160 | [author], 1), |
| 161 | ('man/client', 'labgrid-client', 'labgrid\'s client interface to control boards', |
| 162 | [author], 1), |
| 163 | ('man/coordinator', 'labgrid-coordinator', 'managing labgrid resources and places', |
| 164 | [author], 1), |
| 165 | ('man/device-config', 'labgrid-device-config', 'test configuration files', |
| 166 | [author], 5), |
| 167 | ('man/exporter', 'labgrid-exporter', 'interface to control boards', |
| 168 | [author], 1), |
| 169 | ('man/pytest', 'labgrid-pytest', 'labgrid integration for pytest', |
| 170 | [author], 7), |
| 171 | ('man/suggest', 'labgrid-suggest', 'generator for YAML config files', |
| 172 | [author], 1), |
| 173 | ] |
| 174 | |
| 175 | |
| 176 | # -- Options for Texinfo output ------------------------------------------- |
| 177 | |
| 178 | # Grouping the document tree into Texinfo files. List of tuples |
| 179 | # (source start file, target name, title, author, |
| 180 | # dir menu entry, description, category) |
| 181 | texinfo_documents = [ |
| 182 | (master_doc, 'labgrid', 'labgrid Documentation', |
| 183 | author, 'labgrid', 'One line description of project.', |
| 184 | 'Miscellaneous'), |
| 185 | ] |
| 186 | |
| 187 | |
| 188 | # -- Options for autodoc -------------------------------------------------- |
| 189 | |
| 190 | autodoc_member_order = 'bysource' |
| 191 | # TODO: __annotate_func__ can be dropped once |
| 192 | # https://github.com/sphinx-doc/sphinx/commit/78148440556d3e5962771c1025c85b253ccd73c8 |
| 193 | # is part of a sphinx release |
| 194 | autodoc_default_options = { |
| 195 | 'special-members': True, |
| 196 | 'exclude-members': '__annotate_func__', |
| 197 | } |
| 198 | autodoc_mock_imports = ['onewire', |
| 199 | 'gi', |
| 200 | 'gi.repository', |
| 201 | 'vxi11', |
| 202 | 'pysnmp', |
| 203 | 'kasa', |
| 204 | 'kasa.iot', |
| 205 | ] |
| 206 | |
| 207 | # -- Options for autosection ---------------------------------------------- |
| 208 | autosectionlabel_prefix_document = True |
| 209 | |
| 210 | |
| 211 | from unittest.mock import Mock |
| 212 | for mod in autodoc_mock_imports: |
| 213 | sys.modules[mod] = Mock() |
| 214 | |
| 215 | def run_apidoc(app): |
| 216 | from sphinx.ext.apidoc import main |
| 217 | module = os.path.abspath(os.path.join(app.srcdir, '..', 'labgrid')) |
| 218 | output = os.path.abspath(os.path.join(app.srcdir, 'modules')) |
| 219 | cmd = [module, '-a', '-M', '-H', 'Modules', '-o', output] |
| 220 | main(cmd) |
| 221 | |
| 222 | def setup(app): |
| 223 | # Make version and date stable when generating manpages as they will be tracked in git |
| 224 | if app.outdir.parts[-1] == "man": |
| 225 | app.config.version = "" |
| 226 | app.config.today = "2025" |
| 227 | app.connect('builder-inited', run_apidoc) |
| 228 | app.connect('doctree-read', write_literal_blocks) |
| 229 | |
| 230 | # -- Options for doctest -------------------------------------------------- |
| 231 | |
| 232 | doctest_global_setup = ''' |
| 233 | import os |
| 234 | import shutil |
| 235 | from unittest.mock import Mock, patch |
| 236 | |
| 237 | doctest_dir = '.build/doctest' |
| 238 | |
| 239 | if not os.getcwd().endswith(doctest_dir): |
| 240 | os.chdir(doctest_dir) |
| 241 | ''' |
| 242 | |
| 243 | doctest_global_cleanup = ''' |
| 244 | if os.getcwd().endswith(doctest_dir): |
| 245 | os.chdir('../..') |
| 246 | ''' |
| 247 | |
| 248 | def write_literal_blocks(app, doctree): |
| 249 | """ |
| 250 | Writes named literal blocks to a file with that respective name in the temporary doctest build |
| 251 | directory. This allows doctest to test code snippets referring to these files as-is. |
| 252 | """ |
| 253 | blocks = doctree.traverse( |
| 254 | condition=lambda node: node.tagname == 'literal_block' |
| 255 | ) |
| 256 | |
| 257 | for block in blocks: |
| 258 | name = '_'.join(block['names']) |
| 259 | |
| 260 | if not name: |
| 261 | continue |
| 262 | |
| 263 | out_path = os.path.join(app.outdir, name) |
| 264 | |
| 265 | if os.path.exists(out_path): |
| 266 | raise Exception(f'literal block name "{name}" used multiple times') |
| 267 | |
| 268 | with open(out_path, 'w') as f: |
| 269 | f.write(block.astext()) |