1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Pigweed's Sphinx configuration.""" 15 16from datetime import date 17 18 19from pw_console.pigweed_code_style import PigweedCodeStyle 20from pw_console.pigweed_code_style import PigweedCodeLightStyle 21 22# The suffix of source filenames. 23source_suffix = ['.rst'] 24 25# The master toctree document. # inclusive-language: ignore 26master_doc = 'index' 27 28# General information about the project. 29project = 'Pigweed' 30copyright = f'{date.today().year} The Pigweed Authors' # pylint: disable=redefined-builtin 31 32# The version info for the project you're documenting, acts as replacement for 33# |version| and |release|, also used in various other places throughout the 34# built documents. 35# 36# The short X.Y version. 37version = '0.1' 38# The full version, including alpha/beta/rc tags. 39release = '0.1.0' 40 41 42# Pygments plugin approach (https://pygments.org/docs/plugins/) for getting 43# Sphinx to use our custom styles doesn't work. Use this approach instead: 44# https://stackoverflow.com/q/48615629/1669860 45def pygments_monkeypatch_style(mod_name, cls): 46 import sys 47 import pygments.styles 48 49 cls_name = cls.__name__ 50 mod = type(__import__('os'))(mod_name) 51 setattr(mod, cls_name, cls) 52 setattr(pygments.styles, mod_name, mod) 53 sys.modules['pygments.styles.' + mod_name] = mod 54 from pygments.styles import STYLE_MAP 55 56 STYLE_MAP[mod_name] = mod_name + '::' + cls_name 57 58 59pygments_monkeypatch_style('pigweed_code_style', PigweedCodeStyle) 60pygments_monkeypatch_style('pigweed_code_light_style', PigweedCodeLightStyle) 61 62extensions = [ 63 "pw_docgen.sphinx.bug", 64 "pw_docgen.sphinx.google_analytics", # Enables optional Google Analytics 65 "pw_docgen.sphinx.kconfig", 66 "pw_docgen.sphinx.module_metadata", 67 "pw_docgen.sphinx.modules_index", 68 "pw_docgen.sphinx.pigweed_live", 69 "pw_docgen.sphinx.pw_status_codes", 70 "pw_docgen.sphinx.seed_metadata", 71 "sphinx.ext.autodoc", # Automatic documentation for Python code 72 "sphinx.ext.napoleon", # Parses Google-style docstrings 73 "sphinxarg.ext", # Automatic documentation of Python argparse 74 "sphinxcontrib.mermaid", 75 "sphinx_design", 76 "breathe", 77 "sphinx_copybutton", # Copy-to-clipboard button on code blocks 78 "sphinx_reredirects", 79 "sphinx_sitemap", 80] 81 82# When a user clicks the copy-to-clipboard button the `$ ` prompt should not be 83# copied: https://sphinx-copybutton.readthedocs.io/en/latest/use.html 84copybutton_prompt_text = "$ " 85 86_DIAG_HTML_IMAGE_FORMAT = 'SVG' 87blockdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT 88nwdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT 89seqdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT 90actdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT 91rackdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT 92packetdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT 93 94# Tell m2r to parse links to .md files and add them to the build. 95m2r_parse_relative_links = True 96 97# The theme to use for HTML and HTML Help pages. See the documentation for 98# a list of builtin themes. 99html_theme = 'pydata_sphinx_theme' 100 101# The name for this set of Sphinx documents. If None, it defaults to 102# "<project> v<release> documentation". 103html_title = 'Pigweed' 104 105# If true, SmartyPants will be used to convert quotes and dashes to 106# typographically correct entities. 107html_use_smartypants = True 108 109# If false, no module index is generated. 110html_domain_indices = True 111 112html_favicon = 'docs/_static/pw_logo.ico' 113html_logo = 'docs/_static/pw_logo.svg' 114 115# If false, no index is generated. 116html_use_index = True 117 118# If true, the index is split into individual pages for each letter. 119html_split_index = False 120 121# If true, links to the reST sources are added to the pages. 122html_show_sourcelink = False 123 124# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 125html_show_sphinx = False 126 127# These folders are copied to the documentation's HTML output 128html_static_path = ['docs/_static'] 129 130# These paths are either relative to html_static_path 131# or fully qualified paths (eg. https://...) 132html_css_files = [ 133 "css/pigweed.css", 134 # We could potentially merge the Google Fonts stylesheets into a single network 135 # request but we already preconnect with the service in //docs/layout/layout.html 136 # so the performance impact of keeping these as 3 separate calls should be 137 # negligible. 138 "https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&display=swap", 139 "https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap", 140 "https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap", 141 # FontAwesome for mermaid and sphinx-design 142 "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css", 143] 144 145html_js_files = [ 146 "js/pigweed.js", 147 # Needed for sidebar search 148 "https://cdnjs.cloudflare.com/ajax/libs/fuzzysort/2.0.4/fuzzysort.js", 149] 150 151html_extra_path = [ 152 # Note: In this repo the file lives at //docs/blog/rss.xml but during the 153 # Sphinx build it's copied to the root of the website, https://pigweed.dev/rss.xml 154 'docs/blog/rss.xml', 155] 156 157html_theme_options = { 158 # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/header-links.html#navigation-bar-dropdown-links 159 'header_links_before_dropdown': 5, 160 # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/header-links.html#icon-links 161 'icon_links': [ 162 { 163 'name': 'Source code', 164 'url': 'https://cs.opensource.google/pigweed/pigweed/', 165 'icon': 'fa-solid fa-code', 166 }, 167 { 168 'name': 'Issue tracker', 169 'url': 'https://pwbug.dev', 170 'icon': 'fa-solid fa-bug', 171 }, 172 { 173 'name': 'Discord', 174 'url': 'https://discord.com/channels/691686718377558037/691686718377558040', 175 'icon': 'fa-brands fa-discord', 176 }, 177 ], 178 # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/branding.html 179 'logo': { 180 'text': 'Pigweed', 181 'image_light': '_static/pw_logo.svg', 182 'image_dark': '_static/pw_logo.svg', 183 }, 184 # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/layout.html#configure-the-navbar-center-alignment 185 'navbar_align': 'right', 186 # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/styling.html#configure-pygments-theme 187 'pygments_light_style': 'pigweed_code_light_style', 188 'pygments_dark_style': 'pigweed_code_style', 189} 190 191# sphinx-sitemap needs this: 192# https://sphinx-sitemap.readthedocs.io/en/latest/getting-started.html#usage 193html_baseurl = 'https://pigweed.dev/' 194 195# Hide "Section Navigation" on homepage and changelog. 196html_sidebars = {'index': [], 'changelog': []} 197 198html_context = { 199 'default_mode': 'dark', 200} 201 202# https://sphinx-sitemap.readthedocs.io/en/latest/advanced-configuration.html 203sitemap_url_scheme = '{link}' 204 205mermaid_init_js = ''' 206mermaid.initialize({ 207 // Mermaid is manually started in //docs/_static/js/pigweed.js. 208 startOnLoad: false, 209 // sequenceDiagram Note text alignment 210 noteAlign: "left", 211 // Set mermaid theme to the current furo theme 212 theme: localStorage.getItem("theme") == "dark" ? "dark" : "default" 213}); 214''' 215 216# Output file base name for HTML help builder. 217htmlhelp_basename = 'Pigweeddoc' 218 219# Client-side redirects. See //docs/contributing/docs/website.rst. 220# Use relative URLs and provide the full path to ensure that the 221# redirects work when developing locally. An example of using the 222# full path is `./example/docs.html`. Using just `./example/` 223# assumes that the redirect will work, which may not be true during 224# local development. 225redirects = { 226 'docs/contributing': './contributing/index.html', 227 'docs/contributing/changelog': './docs/changelog.html', 228 'docs/contributing/module_docs': './docs/modules.html', 229 'docs/getting_started': './get_started/index.html', 230 'docs/infra/github': '../get_started/github.html', 231 'docs/os_abstraction_layers': './os/index.html', 232 'docs/release_notes/index': '../../changelog.html', 233 'docs/release_notes/2022_jan': '../../changelog.html', 234 'live/index': 'https://docs.google.com/document/d/1zcXQoMX6NDSe4cdxzt8afLbDcs8GSmI_Bsy5hTF_RVM/edit', 235 'module_guides': './modules.html', 236 'pw_sys_io_pico/docs': '../pw_sys_io_rp2040/docs.html', 237 'pw_tokenizer/cli': './docs.html', 238 'pw_tokenizer/guides': './docs.html', 239 'seed/0000-index': './0000.html', 240 'seed/0001-the-seed-process': './0001.html', 241 'seed/0002-template': './0002.html', 242 'seed/0101-pigweed.json': './0101.html', 243 'seed/0102-module-docs': './0102.html', 244 'seed/0103-pw_protobuf-past-present-future': './0103.html', 245 'seed/0104-display-support': './0104.html', 246 'seed/0105-pw_tokenizer-pw_log-nested-tokens': './0105.html', 247 'seed/0107-communications': './0107.html', 248 'seed/0108-pw_emu-emulators-frontend': './0108.html', 249 'seed/0109-comms-buffers': './0109.html', 250 'seed/0110-memory-allocation-interfaces': './0110.html', 251 'seed/0111-build-systems': './0111.html', 252 'seed/0112-async-poll': './0112.html', 253 'seed/0113-bazel-cc-toolchain-api': './0113.html', 254 'seed/0114-channels': './0114.html', 255 'seed/0117-pw_i3c': './0117.html', 256 'seed/0119-pw-sensor': './0119.html', 257 'seed/0120-pw-sensor-config': './0120.html', 258 'seed/0122-code-samples': './0122.html', 259 'seed/0124-multisink-size-info': './0124.html', 260 'seed/0128-abstracting-thread-creation': './0128.html', 261 'seed/0130-update-sphinx-theme': './0130.html', 262 'seeds/index': '../seed/0000-index.html', 263 'sense/index': '../docs/showcases/sense/', 264 'tour/index': '../docs/showcases/sense/', 265} 266 267# One entry per manual page. List of tuples 268# (source start file, name, description, authors, manual section). 269man_pages = [('index', 'pigweed', 'Pigweed', ['Google'], 1)] 270 271# Grouping the document tree into Texinfo files. List of tuples 272# (source start file, target name, title, author, 273# dir menu entry, description, category) 274texinfo_documents = [ 275 ( 276 'index', 277 'Pigweed', 278 'Pigweed', 279 'Google', 280 'Pigweed', 281 'Firmware framework', 282 'Miscellaneous', 283 ), 284] 285 286templates_path = ['docs/layout'] 287exclude_patterns = ['docs/templates/**'] 288 289breathe_projects = { 290 # Assuming doxygen output is at out/docs/doxygen/ 291 # This dir should be relative to out/docs/gen/docs/pw_docgen_tree/ 292 "Pigweed": "./../../../doxygen/xml/", 293} 294breathe_default_project = "Pigweed" 295breathe_debug_trace_directives = True 296# (b/295023422) Disable the inaccurate `#include` statements that are generated 297# when `doxygennamespace` is used. 298breathe_show_include = False 299 300# Treat these as valid attributes in function signatures. 301cpp_id_attributes = [ 302 "PW_EXTERN_C_START", 303 "PW_NO_LOCK_SAFETY_ANALYSIS", 304] 305# This allows directives like this to work: 306# .. cpp:function:: inline bool try_lock_for( 307# chrono::SystemClock::duration timeout) PW_EXCLUSIVE_TRYLOCK_FUNCTION(true) 308cpp_paren_attributes = [ 309 "PW_EXCLUSIVE_TRYLOCK_FUNCTION", 310 "PW_EXCLUSIVE_LOCK_FUNCTION", 311 "PW_UNLOCK_FUNCTION", 312 "PW_NO_SANITIZE", 313] 314# inclusive-language: disable 315# Info on cpp_id_attributes and cpp_paren_attributes 316# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-cpp_id_attributes 317# inclusive-language: enable 318 319# Disable Python type hints 320# autodoc_typehints = 'none' 321 322# Break class and function signature arguments into one arg per line if the 323# total length exceeds 130 characters. 130 seems about right for keeping one or 324# two parameters on a single line. 325maximum_signature_line_length = 130 326 327 328def do_not_skip_init(app, what, name, obj, would_skip, options): 329 if name == "__init__": 330 return False # never skip __init__ functions 331 return would_skip 332 333 334# Problem: CSS files aren't copied after modifying them. Solution: 335# https://github.com/sphinx-doc/sphinx/issues/2090#issuecomment-572902572 336def env_get_outdated(app, env, added, changed, removed): 337 return ['index'] 338 339 340def setup(app): 341 app.add_css_file('css/pigweed.css') 342 app.connect('env-get-outdated', env_get_outdated) 343 app.connect("autodoc-skip-member", do_not_skip_init) 344