• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17import sphinx
18
19# The suffix of source filenames.
20source_suffix = ['.rst']
21
22# The master toctree document.  # inclusive-language: ignore
23master_doc = 'index'
24
25# General information about the project.
26project = 'Pigweed'
27copyright = f'{date.today().year} The Pigweed Authors'  # pylint: disable=redefined-builtin
28
29# The version info for the project you're documenting, acts as replacement for
30# |version| and |release|, also used in various other places throughout the
31# built documents.
32#
33# The short X.Y version.
34version = '0.1'
35# The full version, including alpha/beta/rc tags.
36release = '0.1.0'
37
38# The class of the Pygments (syntax highlighting) style to use.
39pygments_style = 'pw_console.pigweed_code_style.PigweedCodeLightStyle'
40pygments_dark_style = 'pw_console.pigweed_code_style.PigweedCodeStyle'
41
42extensions = [
43    "pw_docgen.sphinx.google_analytics",  # Enables optional Google Analytics
44    "pw_docgen.sphinx.kconfig",
45    "pw_docgen.sphinx.module_metadata",
46    "pw_docgen.sphinx.pigweed_live",
47    "pw_docgen.sphinx.pw_status_codes",
48    "pw_docgen.sphinx.inlinesearch",
49    "pw_docgen.sphinx.seed_metadata",
50    "sphinx.ext.autodoc",  # Automatic documentation for Python code
51    "sphinx.ext.napoleon",  # Parses Google-style docstrings
52    "sphinxarg.ext",  # Automatic documentation of Python argparse
53    "sphinxcontrib.mermaid",
54    "sphinx_design",
55    "breathe",
56    "sphinx_copybutton",  # Copy-to-clipboard button on code blocks
57    "sphinx_reredirects",
58    "sphinx_sitemap",
59]
60
61# When a user clicks the copy-to-clipboard button the `$ ` prompt should not be
62# copied: https://sphinx-copybutton.readthedocs.io/en/latest/use.html
63copybutton_prompt_text = "$ "
64
65_DIAG_HTML_IMAGE_FORMAT = 'SVG'
66blockdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT
67nwdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT
68seqdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT
69actdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT
70rackdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT
71packetdiag_html_image_format = _DIAG_HTML_IMAGE_FORMAT
72
73# Tell m2r to parse links to .md files and add them to the build.
74m2r_parse_relative_links = True
75
76# The theme to use for HTML and HTML Help pages.  See the documentation for
77# a list of builtin themes.
78html_theme = 'furo'
79
80# The name for this set of Sphinx documents.  If None, it defaults to
81# "<project> v<release> documentation".
82html_title = 'Pigweed'
83
84# If true, SmartyPants will be used to convert quotes and dashes to
85# typographically correct entities.
86html_use_smartypants = True
87
88# If false, no module index is generated.
89html_domain_indices = True
90
91html_favicon = 'docs/_static/pw_logo.ico'
92html_logo = 'docs/_static/pw_logo.svg'
93
94# If false, no index is generated.
95html_use_index = True
96
97# If true, the index is split into individual pages for each letter.
98html_split_index = False
99
100# If true, links to the reST sources are added to the pages.
101html_show_sourcelink = False
102
103# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
104html_show_sphinx = False
105
106# These folders are copied to the documentation's HTML output
107html_static_path = ['docs/_static']
108
109# These paths are either relative to html_static_path
110# or fully qualified paths (eg. https://...)
111html_css_files = [
112    "css/pigweed.css",
113    # Needed for Inconsolata font.
114    "https://fonts.googleapis.com/css2?family=Inconsolata&display=swap",
115    # FontAwesome for mermaid and sphinx-design
116    "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css",
117]
118
119html_js_files = [
120    "js/pigweed.js",
121    # Needed for sidebar search
122    "https://cdnjs.cloudflare.com/ajax/libs/fuzzysort/2.0.4/fuzzysort.js",
123]
124
125# Furo color theme variables based on:
126# https://github.com/pradyunsg/furo/blob/main/src/furo/assets/styles/variables/_colors.scss
127# Colors with unchanged defaults are left commented out for easy updating.
128html_theme_options = {
129    'light_css_variables': {
130        # Make the logo text more amaranth-like
131        'color-sidebar-brand-text': '#b529aa',
132        'color-sidebar-search-border': '#b529aa',
133        'color-sidebar-link-text--top-level': '#85004d',
134        'color-sidebar-link-text': '#016074',
135        'color-sidebar-item-background--current': '#f0f0f0',
136        'color-sidebar-item-background--hover': '#ffe2f3',
137        'color-sidebar-item-expander-background--hover': '#ffe2f3',
138        # Function signature colors
139        'color-api-function-border': '#cccccc',
140        'color-api-function-background': '#f0f0f0',
141        'color-api-class-background': '#e7f2fa',
142        'color-api-class-foreground': '#2980b9',
143        'color-api-class-border': '#6ab0de',
144        # Namespace::
145        'color-api-pre-name': '#2980b9',
146        # Function name
147        'color-api-name': '#2980b9',
148        'color-inline-code-background': '#fafafa',
149        'color-inline-code-border': '#cccccc',
150        'color-text-selection-background': '#1d5fad',
151        'color-text-selection-foreground': '#ffffff',
152        # Background color for focused headings.
153        'color-highlight-on-target': '#ffffcc',
154        # Background color emphasized code lines.
155        'color-code-hll-background': '#ffffcc',
156        'color-section-button': '#b529aa',
157        'color-section-button-hover': '#fb71fe',
158    },
159    'dark_css_variables': {
160        'color-sidebar-brand-text': '#fb71fe',
161        'color-sidebar-search-border': '#e815a5',
162        'color-sidebar-link-text--top-level': '#ff79c6',
163        'color-sidebar-link-text': '#8be9fd',
164        'color-sidebar-item-background--current': '#2a3037',
165        'color-sidebar-item-background--hover': '#30353d',
166        'color-sidebar-item-expander-background--hover': '#4c333f',
167        # Function signature colors
168        'color-api-function-border': '#575757',
169        'color-api-function-background': '#2b2b2b',
170        'color-api-class-background': '#222c35',
171        'color-api-class-foreground': '#87c1e5',
172        'color-api-class-border': '#5288be',
173        # Namespace::
174        'color-api-pre-name': '#87c1e5',
175        # Function name
176        'color-api-name': '#87c1e5',
177        'color-code-background': '#2d333b',
178        'color-inline-code-background': '#2d333b',
179        'color-inline-code-border': '#575757',
180        'color-text-selection-background': '#2674bf',
181        'color-text-selection-foreground': '#ffffff',
182        # Background color for focused headings.
183        'color-highlight-on-target': '#ffc55140',
184        # Background color emphasized code lines.
185        'color-code-hll-background': '#ffc55140',
186        'color-section-button': '#fb71fe',
187        'color-section-button-hover': '#b529aa',
188        # The following color changes modify Furo's default dark mode colors for
189        # slightly less high-contrast.
190        # Base Colors
191        # 'color-foreground-primary': '#ffffffcc', # Main text and headings
192        # 'color-foreground-secondary': '#9ca0a5', # Secondary text
193        # 'color-foreground-muted': '#81868d', # Muted text
194        # 'color-foreground-border': '#666666', # Content borders
195        'color-background-primary': '#1c2128',  # Content
196        'color-background-secondary': '#22272e',  # Navigation and TOC
197        'color-background-hover': '#30353dff',  # Navigation-item hover
198        'color-background-hover--transparent': '#30353d00',
199        'color-background-border': '#444c56',  # UI borders
200        'color-background-item': '#373e47',  # "background" items (eg: copybutton)
201        # Announcements
202        # 'color-announcement-background': '#000000dd',
203        # 'color-announcement-text': '#eeebee',
204        # Brand colors
205        # 'color-brand-primary': '#2b8cee',
206        # 'color-brand-content': '#368ce2',
207        # Highlighted text (search)
208        # 'color-highlighted-background': '#083563',
209        # GUI Labels
210        # 'color-guilabel-background': '#08356380',
211        # 'color-guilabel-border': '#13395f80',
212        # API documentation
213        # 'color-api-keyword': 'var(--color-foreground-secondary)',
214        # 'color-highlight-on-target': '#333300',
215        # Admonitions
216        'color-admonition-background': 'var(--color-background-secondary)',
217        # Cards
218        'color-card-border': 'var(--color-background-border)',
219        'color-card-background': 'var(--color-background-secondary)',
220        # 'color-card-marginals-background': 'var(--color-background-hover)',
221        # Sphinx Design cards
222        'sd-color-card-background': 'var(--color-background-secondary)',
223        'sd-color-card-border': 'var(--color-background-border)',
224    },
225}
226
227# sphinx-sitemap needs this:
228# https://sphinx-sitemap.readthedocs.io/en/latest/getting-started.html#usage
229html_baseurl = 'https://pigweed.dev/'
230
231# https://sphinx-sitemap.readthedocs.io/en/latest/advanced-configuration.html
232sitemap_url_scheme = '{link}'
233
234mermaid_init_js = '''
235mermaid.initialize({
236  // Mermaid is manually started in //docs/_static/js/pigweed.js.
237  startOnLoad: false,
238  // sequenceDiagram Note text alignment
239  noteAlign: "left",
240  // Set mermaid theme to the current furo theme
241  theme: localStorage.getItem("theme") == "dark" ? "dark" : "default"
242});
243'''
244
245# Output file base name for HTML help builder.
246htmlhelp_basename = 'Pigweeddoc'
247
248# Client-side redirects. See //docs/contributing/docs/website.rst.
249# Use relative URLs and provide the full path to ensure that the
250# redirects work when developing locally. An example of using the
251# full path is `./example/docs.html`. Using just `./example/`
252# assumes that the redirect will work, which may not be true during
253# local development.
254redirects = {
255    'docs/contributing': './contributing/index.html',
256    'docs/contributing/changelog': './docs/changelog.html',
257    'docs/contributing/module_docs': './docs/modules.html',
258    'docs/getting_started': './get_started/index.html',
259    'docs/os_abstraction_layers': './os/index.html',
260    'docs/release_notes/index': '../../changelog.html',
261    'docs/release_notes/2022_jan': '../../changelog.html',
262    'module_guides': './modules.html',
263    'pw_sys_io_pico/docs': '../pw_sys_io_rp2040/docs.html',
264    'pw_tokenizer/cli': './docs.html',
265    'pw_tokenizer/guides': './docs.html',
266}
267
268# One entry per manual page. List of tuples
269# (source start file, name, description, authors, manual section).
270man_pages = [('index', 'pigweed', 'Pigweed', ['Google'], 1)]
271
272# Grouping the document tree into Texinfo files. List of tuples
273# (source start file, target name, title, author,
274#  dir menu entry, description, category)
275texinfo_documents = [
276    (
277        'index',
278        'Pigweed',
279        'Pigweed',
280        'Google',
281        'Pigweed',
282        'Firmware framework',
283        'Miscellaneous',
284    ),
285]
286
287templates_path = ['docs/layout']
288exclude_patterns = ['docs/templates/**']
289
290breathe_projects = {
291    # Assuming doxygen output is at out/docs/doxygen/
292    # This dir should be relative to out/docs/gen/docs/pw_docgen_tree/
293    "Pigweed": "./../../../doxygen/xml/",
294}
295breathe_default_project = "Pigweed"
296breathe_debug_trace_directives = True
297# (b/295023422) Disable the inaccurate `#include` statements that are generated
298# when `doxygennamespace` is used.
299breathe_show_include = False
300
301# Treat these as valid attributes in function signatures.
302cpp_id_attributes = [
303    "PW_EXTERN_C_START",
304    "PW_NO_LOCK_SAFETY_ANALYSIS",
305]
306# This allows directives like this to work:
307# .. cpp:function:: inline bool try_lock_for(
308#     chrono::SystemClock::duration timeout) PW_EXCLUSIVE_TRYLOCK_FUNCTION(true)
309cpp_paren_attributes = [
310    "PW_EXCLUSIVE_TRYLOCK_FUNCTION",
311    "PW_EXCLUSIVE_LOCK_FUNCTION",
312    "PW_UNLOCK_FUNCTION",
313    "PW_NO_SANITIZE",
314]
315# inclusive-language: disable
316# Info on cpp_id_attributes and cpp_paren_attributes
317# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-cpp_id_attributes
318# inclusive-language: enable
319
320# Disable Python type hints
321# autodoc_typehints = 'none'
322
323# Break class and function signature arguments into one arg per line if the
324# total length exceeds 130 characters. 130 seems about right for keeping one or
325# two parameters on a single line.
326maximum_signature_line_length = 130
327
328
329def do_not_skip_init(app, what, name, obj, would_skip, options):
330    if name == "__init__":
331        return False  # never skip __init__ functions
332    return would_skip
333
334
335# Problem: CSS files aren't copied after modifying them. Solution:
336# https://github.com/sphinx-doc/sphinx/issues/2090#issuecomment-572902572
337def env_get_outdated(app, env, added, changed, removed):
338    return ['index']
339
340
341def setup(app):
342    app.add_css_file('css/pigweed.css')
343    app.connect('env-get-outdated', env_get_outdated)
344    app.connect("autodoc-skip-member", do_not_skip_init)
345