conf.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 = "4.0"
  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%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. # To be able to use :manpage:`<something>` in the docs.
  100. manpages_url = 'https://manpages.debian.org/{path}'
  101. # Intersphinx config to use cross reference with BitBake user manual
  102. intersphinx_mapping = {
  103. 'bitbake': ('https://docs.yoctoproject.org/bitbake/' + bitbake_version, None)
  104. }
  105. # Suppress "WARNING: unknown mimetype for ..."
  106. suppress_warnings = ['epub.unknown_project_files']
  107. # -- Options for HTML output -------------------------------------------------
  108. # The theme to use for HTML and HTML Help pages. See the documentation for
  109. # a list of builtin themes.
  110. #
  111. try:
  112. import sphinx_rtd_theme
  113. html_theme = 'sphinx_rtd_theme'
  114. html_theme_options = {
  115. 'sticky_navigation': False,
  116. }
  117. except ImportError:
  118. sys.stderr.write("The Sphinx sphinx_rtd_theme HTML theme was not found.\
  119. \nPlease make sure to install the sphinx_rtd_theme Python package.\n")
  120. sys.exit(1)
  121. html_logo = 'sphinx-static/YoctoProject_Logo_RGB.jpg'
  122. html_favicon = 'sphinx-static/favicon.ico'
  123. # Add any paths that contain custom static files (such as style sheets) here,
  124. # relative to this directory. They are copied after the builtin static files,
  125. # so a file named "default.css" will overwrite the builtin "default.css".
  126. html_static_path = ['sphinx-static']
  127. html_context = {
  128. 'current_version': current_version,
  129. }
  130. # Add customm CSS and JS files
  131. html_css_files = ['theme_overrides.css']
  132. html_js_files = ['switchers.js']
  133. # Hide 'Created using Sphinx' text
  134. html_show_sphinx = False
  135. # Add 'Last updated' on each page
  136. html_last_updated_fmt = '%b %d, %Y'
  137. # Remove the trailing 'dot' in section numbers
  138. html_secnumber_suffix = " "
  139. # We need XeTeX to process special unicode character, sometimes the contributor
  140. # list from the release note contains those.
  141. # See https://docs.readthedocs.io/en/stable/guides/pdf-non-ascii-languages.html.
  142. latex_engine = 'xelatex'
  143. latex_use_xindy = False
  144. latex_elements = {
  145. 'passoptionstopackages': '\\PassOptionsToPackage{bookmarksdepth=5}{hyperref}',
  146. 'preamble': '\\usepackage[UTF8]{ctex}\n\\setcounter{tocdepth}{2}',
  147. }
  148. from sphinx.search import SearchEnglish
  149. from sphinx.search import languages
  150. class DashFriendlySearchEnglish(SearchEnglish):
  151. # Accept words that can include hyphens
  152. _word_re = re.compile(r'[\w\-]+')
  153. js_splitter_code = """
  154. function splitQuery(query) {
  155. return query
  156. .split(/[^\p{Letter}\p{Number}_\p{Emoji_Presentation}-]+/gu)
  157. .filter(term => term.length > 0);
  158. }
  159. """
  160. languages['en'] = DashFriendlySearchEnglish
  161. # Make the EPUB builder prefer PNG to SVG because of issues rendering Inkscape SVG
  162. from sphinx.builders.epub3 import Epub3Builder
  163. Epub3Builder.supported_image_types = ['image/png', 'image/gif', 'image/jpeg']