conf.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # Configuration file for the Sphinx documentation builder.
  2. #
  3. # SPDX-License-Identifier: CC-BY-SA-2.0-UK
  4. #
  5. # This file only contains a selection of the most common options. For a full
  6. # list see the documentation:
  7. # https://www.sphinx-doc.org/en/master/usage/configuration.html
  8. # -- Path setup --------------------------------------------------------------
  9. # If extensions (or modules to document with autodoc) are in another directory,
  10. # add these directories to sys.path here. If the directory is relative to the
  11. # documentation root, use os.path.abspath to make it absolute, like shown here.
  12. #
  13. import os
  14. import re
  15. import sys
  16. import datetime
  17. try:
  18. import yaml
  19. except ImportError:
  20. sys.stderr.write("The Yocto Project Sphinx documentation requires PyYAML.\
  21. \nPlease make sure to install pyyaml python package.\n")
  22. sys.exit(1)
  23. # current_version = "dev"
  24. # bitbake_version = "" # Leave empty for development branch
  25. # Obtain versions from poky.yaml instead
  26. with open("poky.yaml") as data:
  27. buff = data.read()
  28. subst_vars = yaml.safe_load(buff)
  29. if "DOCCONF_VERSION" not in subst_vars:
  30. sys.stderr.write("Please set DOCCONF_VERSION in poky.yaml")
  31. sys.exit(1)
  32. current_version = subst_vars["DOCCONF_VERSION"]
  33. if "BITBAKE_SERIES" not in subst_vars:
  34. sys.stderr.write("Please set BITBAKE_SERIES in poky.yaml")
  35. sys.exit(1)
  36. bitbake_version = subst_vars["BITBAKE_SERIES"]
  37. # String used in sidebar
  38. version = 'Version: ' + current_version
  39. if current_version == 'dev':
  40. version = 'Version: Current Development'
  41. # Version seen in documentation_options.js and hence in js switchers code
  42. release = current_version
  43. # -- Project information -----------------------------------------------------
  44. project = 'The Yocto Project \xae'
  45. copyright = '2010-%s, The Linux Foundation, CC-BY-SA-2.0-UK license' % datetime.datetime.now().year
  46. author = 'The Linux Foundation'
  47. # -- General configuration ---------------------------------------------------
  48. # Prevent building with an outdated version of sphinx
  49. needs_sphinx = "3.1"
  50. # to load local extension from the folder 'sphinx'
  51. sys.path.insert(0, os.path.abspath('sphinx'))
  52. # Add any Sphinx extension module names here, as strings. They can be
  53. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  54. # ones.
  55. extensions = [
  56. 'sphinx.ext.autosectionlabel',
  57. 'sphinx.ext.extlinks',
  58. 'sphinx.ext.intersphinx',
  59. 'yocto-vars'
  60. ]
  61. autosectionlabel_prefix_document = True
  62. # Add any paths that contain templates here, relative to this directory.
  63. templates_path = ['_templates']
  64. # List of patterns, relative to source directory, that match files and
  65. # directories to ignore when looking for source files.
  66. # This pattern also affects html_static_path and html_extra_path.
  67. exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'boilerplate.rst']
  68. # master document name. The default changed from contents to index. so better
  69. # set it ourselves.
  70. master_doc = 'index'
  71. # create substitution for project configuration variables
  72. rst_prolog = """
  73. .. |project_name| replace:: %s
  74. .. |copyright| replace:: %s
  75. .. |author| replace:: %s
  76. """ % (project, copyright, author)
  77. # external links and substitutions
  78. extlinks = {
  79. 'bitbake_git': ('https://git.openembedded.org/bitbake%s', None),
  80. 'cve_mitre': ('https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s', 'CVE-%s'),
  81. 'cve_nist': ('https://nvd.nist.gov/vuln/detail/CVE-%s', 'CVE-%s'),
  82. 'yocto_home': ('https://www.yoctoproject.org%s', None),
  83. 'yocto_wiki': ('https://wiki.yoctoproject.org/wiki%s', None),
  84. 'yocto_dl': ('https://downloads.yoctoproject.org%s', None),
  85. 'yocto_lists': ('https://lists.yoctoproject.org%s', None),
  86. 'yocto_bugs': ('https://bugzilla.yoctoproject.org%s', None),
  87. 'yocto_ab': ('https://autobuilder.yoctoproject.org%s', None),
  88. 'yocto_docs': ('https://docs.yoctoproject.org%s', None),
  89. 'yocto_git': ('https://git.yoctoproject.org/cgit/cgit.cgi%s', None),
  90. 'yocto_sstate': ('http://sstate.yoctoproject.org%s', None),
  91. 'oe_home': ('https://www.openembedded.org%s', None),
  92. 'oe_lists': ('https://lists.openembedded.org%s', None),
  93. 'oe_git': ('https://git.openembedded.org%s', None),
  94. 'oe_wiki': ('https://www.openembedded.org/wiki%s', None),
  95. 'oe_layerindex': ('https://layers.openembedded.org%s', None),
  96. 'oe_layer': ('https://layers.openembedded.org/layerindex/branch/master/layer%s', None),
  97. 'wikipedia': ('https://en.wikipedia.org/wiki/%s', None),
  98. }
  99. # Intersphinx config to use cross reference with Bitbake user manual
  100. intersphinx_mapping = {
  101. 'bitbake': ('https://docs.yoctoproject.org/bitbake/' + bitbake_version, None)
  102. }
  103. # Suppress "WARNING: unknown mimetype for ..."
  104. suppress_warnings = ['epub.unknown_project_files']
  105. # -- Options for HTML output -------------------------------------------------
  106. # The theme to use for HTML and HTML Help pages. See the documentation for
  107. # a list of builtin themes.
  108. #
  109. try:
  110. import sphinx_rtd_theme
  111. html_theme = 'sphinx_rtd_theme'
  112. html_theme_options = {
  113. 'sticky_navigation': False,
  114. }
  115. except ImportError:
  116. sys.stderr.write("The Sphinx sphinx_rtd_theme HTML theme was not found.\
  117. \nPlease make sure to install the sphinx_rtd_theme python package.\n")
  118. sys.exit(1)
  119. html_logo = 'sphinx-static/YoctoProject_Logo_RGB.jpg'
  120. html_favicon = 'sphinx-static/favicon.ico'
  121. # Add any paths that contain custom static files (such as style sheets) here,
  122. # relative to this directory. They are copied after the builtin static files,
  123. # so a file named "default.css" will overwrite the builtin "default.css".
  124. html_static_path = ['sphinx-static']
  125. html_context = {
  126. 'current_version': current_version,
  127. }
  128. # Add customm CSS and JS files
  129. html_css_files = ['theme_overrides.css']
  130. html_js_files = ['switchers.js']
  131. # Hide 'Created using Sphinx' text
  132. html_show_sphinx = False
  133. # Add 'Last updated' on each page
  134. html_last_updated_fmt = '%b %d, %Y'
  135. # Remove the trailing 'dot' in section numbers
  136. html_secnumber_suffix = " "
  137. latex_elements = {
  138. 'passoptionstopackages': '\\PassOptionsToPackage{bookmarksdepth=5}{hyperref}',
  139. 'preamble': '\\setcounter{tocdepth}{2}',
  140. }
  141. from sphinx.search import SearchEnglish
  142. from sphinx.search import languages
  143. class DashFriendlySearchEnglish(SearchEnglish):
  144. # Accept words that can include hyphens
  145. _word_re = re.compile(r'[\w\-]+')
  146. js_splitter_code = """
  147. function splitQuery(query) {
  148. return query
  149. .split(/[^\p{Letter}\p{Number}_\p{Emoji_Presentation}-]+/gu)
  150. .filter(term => term.length > 0);
  151. }
  152. """
  153. languages['en'] = DashFriendlySearchEnglish
  154. # Make the EPUB builder prefer PNG to SVG because of issues rendering Inkscape SVG
  155. from sphinx.builders.epub3 import Epub3Builder
  156. Epub3Builder.supported_image_types = ['image/png', 'image/gif', 'image/jpeg']