conf_common.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Common (non-language-specific) configuration for Read The Docs & Sphinx
  4. #
  5. # Based on a Read the Docs Template documentation build configuration file,
  6. # created by sphinx-quickstart on Tue Aug 26 14:19:49 2014.
  7. #
  8. # This file is imported from a language-specific conf.py (ie en/conf.py or
  9. # zh_CN/conf.py)
  10. #
  11. # Note that not all possible configuration values are present in this
  12. # autogenerated file.
  13. #
  14. # All configuration values have a default; values that are commented out
  15. # serve to show the default.
  16. from __future__ import print_function
  17. from __future__ import unicode_literals
  18. import sys
  19. import os
  20. import os.path
  21. import re
  22. import subprocess
  23. from sanitize_version import sanitize_version
  24. from idf_extensions.util import download_file_if_missing
  25. from get_github_rev import get_github_rev
  26. # build_docs on the CI server sometimes fails under Python3. This is a workaround:
  27. sys.setrecursionlimit(3500)
  28. config_dir = os.path.abspath(os.path.dirname(__file__))
  29. # http://stackoverflow.com/questions/12772927/specifying-an-online-image-in-sphinx-restructuredtext-format
  30. #
  31. suppress_warnings = ['image.nonlocal_uri']
  32. # -- General configuration ------------------------------------------------
  33. # If your documentation needs a minimal Sphinx version, state it here.
  34. # needs_sphinx = '1.0'
  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 = ['breathe',
  39. 'sphinx.ext.todo',
  40. 'sphinx_idf_theme',
  41. 'sphinxcontrib.blockdiag',
  42. 'sphinxcontrib.seqdiag',
  43. 'sphinxcontrib.actdiag',
  44. 'sphinxcontrib.nwdiag',
  45. 'sphinxcontrib.rackdiag',
  46. 'sphinxcontrib.packetdiag',
  47. 'extensions.html_redirects',
  48. 'extensions.toctree_filter',
  49. 'extensions.list_filter',
  50. # Note: order is important here, events must
  51. # be registered by one extension before they can be
  52. # connected to another extension
  53. 'idf_extensions.include_build_file',
  54. 'idf_extensions.link_roles',
  55. 'idf_extensions.build_system',
  56. 'idf_extensions.esp_err_definitions',
  57. 'idf_extensions.gen_toolchain_links',
  58. 'idf_extensions.gen_version_specific_includes',
  59. 'idf_extensions.kconfig_reference',
  60. 'idf_extensions.gen_defines',
  61. 'idf_extensions.run_doxygen',
  62. 'idf_extensions.gen_idf_tools_links',
  63. 'idf_extensions.format_idf_target',
  64. 'idf_extensions.latex_builder',
  65. 'idf_extensions.exclude_docs',
  66. # from https://github.com/pfalcon/sphinx_selective_exclude
  67. 'sphinx_selective_exclude.eager_only',
  68. # TODO: determine if we need search_auto_exclude
  69. # 'sphinx_selective_exclude.search_auto_exclude',
  70. ]
  71. # sphinx.ext.todo extension parameters
  72. # If the below parameter is True, the extension
  73. # produces output, else it produces nothing.
  74. todo_include_todos = False
  75. # Enabling this fixes cropping of blockdiag edge labels
  76. seqdiag_antialias = True
  77. # Add any paths that contain templates here, relative to this directory.
  78. templates_path = ['_templates']
  79. # The suffix of source filenames.
  80. source_suffix = ['.rst', '.md']
  81. source_parsers = {'.md': 'recommonmark.parser.CommonMarkParser',
  82. }
  83. # The encoding of source files.
  84. # source_encoding = 'utf-8-sig'
  85. # The master toctree document.
  86. master_doc = 'index'
  87. # The version info for the project you're documenting, acts as replacement for
  88. # |version| and |release|, also used in various other places throughout the
  89. # built documents.
  90. #
  91. # This is the full exact version, canonical git version description
  92. # visible when you open index.html.
  93. version = subprocess.check_output(['git', 'describe']).strip().decode('utf-8')
  94. # The 'release' version is the same as version for non-CI builds, but for CI
  95. # builds on a branch then it's replaced with the branch name
  96. release = sanitize_version(version)
  97. print('Version: {0} Release: {1}'.format(version, release))
  98. # There are two options for replacing |today|: either, you set today to some
  99. # non-false value, then it is used:
  100. # today = ''
  101. # Else, today_fmt is used as the format for a strftime call.
  102. # today_fmt = '%B %d, %Y'
  103. # List of patterns, relative to source directory, that match files and
  104. # directories to ignore when looking for source files.
  105. exclude_patterns = ['**/inc/**', '_static/', '_build/**']
  106. BT_DOCS = ['api-guides/blufi.rst',
  107. 'api-guides/esp-ble-mesh/**',
  108. 'api-reference/bluetooth/**']
  109. SDMMC_DOCS = ['api-reference/peripherals/sdmmc_host.rst',
  110. 'api-reference/peripherals/sd_pullup_requirements.rst']
  111. SDIO_SLAVE_DOCS = ['api-reference/peripherals/sdio_slave.rst']
  112. MCPWM_DOCS = ['api-reference/peripherals/mcpwm.rst']
  113. LEGACY_DOCS = ['api-guides/build-system-legacy.rst',
  114. 'gnu-make-legacy.rst',
  115. 'api-guides/ulp-legacy.rst',
  116. 'api-guides/unit-tests-legacy.rst',
  117. 'get-started-legacy/**']
  118. ESP32_DOCS = ['api-guides/ulp_instruction_set.rst',
  119. 'api-reference/system/himem.rst',
  120. 'api-guides/RF_calibration.rst',
  121. 'api-reference/system/ipc.rst',
  122. 'security/secure-boot-v1.rst',
  123. 'api-reference/peripherals/secure_element.rst',
  124. 'hw-reference/esp32/**'] + LEGACY_DOCS
  125. ESP32S2_DOCS = ['esp32s2.rst',
  126. 'hw-reference/esp32s2/**',
  127. 'api-guides/ulps2_instruction_set.rst',
  128. 'api-guides/dfu.rst',
  129. 'api-guides/usb-console.rst',
  130. 'api-guides/ulp-risc-v.rst',
  131. 'api-reference/peripherals/hmac.rst',
  132. 'api-reference/peripherals/ds.rst',
  133. 'api-reference/peripherals/spi_slave_hd.rst',
  134. 'api-reference/peripherals/temp_sensor.rst',
  135. 'api-reference/system/async_memcpy.rst']
  136. # format: {tag needed to include: documents to included}, tags are parsed from sdkconfig and peripheral_caps.h headers
  137. conditional_include_dict = {'SOC_BT_SUPPORTED':BT_DOCS,
  138. 'SOC_SDMMC_HOST_SUPPORTED':SDMMC_DOCS,
  139. 'SOC_SDIO_SLAVE_SUPPORTED':SDIO_SLAVE_DOCS,
  140. 'SOC_MCPWM_SUPPORTED':MCPWM_DOCS,
  141. 'esp32':ESP32_DOCS,
  142. 'esp32s2':ESP32S2_DOCS}
  143. # The reST default role (used for this markup: `text`) to use for all
  144. # documents.
  145. # default_role = None
  146. # If true, '()' will be appended to :func: etc. cross-reference text.
  147. # add_function_parentheses = True
  148. # If true, the current module name will be prepended to all description
  149. # unit titles (such as .. function::).
  150. # add_module_names = True
  151. # If true, sectionauthor and moduleauthor directives will be shown in the
  152. # output. They are ignored by default.
  153. # show_authors = False
  154. # The name of the Pygments (syntax highlighting) style to use.
  155. pygments_style = 'sphinx'
  156. # A list of ignored prefixes for module index sorting.
  157. # modindex_common_prefix = []
  158. # If true, keep warnings as "system message" paragraphs in the built documents.
  159. # keep_warnings = False
  160. # Extra options required by sphinx_idf_theme
  161. project_slug = 'esp-idf'
  162. versions_url = 'https://dl.espressif.com/dl/esp-idf/idf_versions.js'
  163. idf_targets = ['esp32', 'esp32s2']
  164. languages = ['en', 'zh_CN']
  165. project_homepage = "https://github.com/espressif/esp-idf"
  166. # -- Options for HTML output ----------------------------------------------
  167. # Custom added feature to allow redirecting old URLs
  168. #
  169. # Redirects should be listed in page_redirects.xt
  170. #
  171. with open("../page_redirects.txt") as f:
  172. lines = [re.sub(" +", " ", line.strip()) for line in f.readlines() if line.strip() != "" and not line.startswith("#")]
  173. for line in lines: # check for well-formed entries
  174. if len(line.split(' ')) != 2:
  175. raise RuntimeError("Invalid line in page_redirects.txt: %s" % line)
  176. html_redirect_pages = [tuple(line.split(' ')) for line in lines]
  177. # The theme to use for HTML and HTML Help pages. See the documentation for
  178. # a list of builtin themes.
  179. html_theme = 'sphinx_idf_theme'
  180. # context used by sphinx_idf_theme
  181. html_context = {
  182. "display_github": True, # Add 'Edit on Github' link instead of 'View page source'
  183. "github_user": "espressif",
  184. "github_repo": "esp-idf",
  185. "github_version": get_github_rev(),
  186. }
  187. # Theme options are theme-specific and customize the look and feel of a theme
  188. # further. For a list of options available for each theme, see the
  189. # documentation.
  190. # html_theme_options = {}
  191. # Add any paths that contain custom themes here, relative to this directory.
  192. # html_theme_path = []
  193. # The name for this set of Sphinx documents. If None, it defaults to
  194. # "<project> v<release> documentation".
  195. # html_title = None
  196. # A shorter title for the navigation bar. Default is the same as html_title.
  197. # html_short_title = None
  198. # The name of an image file (relative to this directory) to place at the top
  199. # of the sidebar.
  200. html_logo = "../_static/espressif-logo.svg"
  201. # The name of an image file (within the static path) to use as favicon of the
  202. # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
  203. # pixels large.
  204. # html_favicon = None
  205. # Add any paths that contain custom static files (such as style sheets) here,
  206. # relative to this directory. They are copied after the builtin static files,
  207. # so a file named "default.css" will overwrite the builtin "default.css".
  208. html_static_path = ['../_static']
  209. # Add any extra paths that contain custom files (such as robots.txt or
  210. # .htaccess) here, relative to this directory. These files are copied
  211. # directly to the root of the documentation.
  212. # html_extra_path = []
  213. # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
  214. # using the given strftime format.
  215. # html_last_updated_fmt = '%b %d, %Y'
  216. # If true, SmartyPants will be used to convert quotes and dashes to
  217. # typographically correct entities.
  218. # html_use_smartypants = True
  219. # Custom sidebar templates, maps document names to template names.
  220. # html_sidebars = {}
  221. # Additional templates that should be rendered to pages, maps page names to
  222. # template names.
  223. # html_additional_pages = {}
  224. # If false, no module index is generated.
  225. # html_domain_indices = True
  226. # If false, no index is generated.
  227. # html_use_index = True
  228. # If true, the index is split into individual pages for each letter.
  229. # html_split_index = False
  230. # If true, links to the reST sources are added to the pages.
  231. # html_show_sourcelink = True
  232. # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
  233. # html_show_sphinx = True
  234. # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
  235. # html_show_copyright = True
  236. # If true, an OpenSearch description file will be output, and all pages will
  237. # contain a <link> tag referring to it. The value of this option must be the
  238. # base URL from which the finished HTML is served.
  239. # html_use_opensearch = ''
  240. # This is the file name suffix for HTML files (e.g. ".xhtml").
  241. # html_file_suffix = None
  242. # Output file base name for HTML help builder.
  243. htmlhelp_basename = 'ReadtheDocsTemplatedoc'
  244. # -- Options for LaTeX output ---------------------------------------------
  245. latex_template_dir = os.path.join(config_dir, 'latex_templates')
  246. preamble = ''
  247. with open(os.path.join(latex_template_dir, 'preamble.tex')) as f:
  248. preamble = f.read()
  249. titlepage = ''
  250. with open(os.path.join(latex_template_dir, 'titlepage.tex')) as f:
  251. titlepage = f.read()
  252. latex_elements = {
  253. 'papersize': 'a4paper',
  254. # Latex figure (float) alignment
  255. 'figure_align':'htbp',
  256. 'pointsize': '10pt',
  257. # Additional stuff for the LaTeX preamble.
  258. 'fncychap': '\\usepackage[Sonny]{fncychap}',
  259. 'preamble': preamble,
  260. 'maketitle': titlepage,
  261. }
  262. # The name of an image file (relative to this directory) to place at the bottom of
  263. # the title page.
  264. latex_logo = "../_static/espressif2.pdf"
  265. latex_engine = 'xelatex'
  266. latex_use_xindy = False
  267. # -- Options for manual page output ---------------------------------------
  268. # One entry per manual page. List of tuples
  269. # (source start file, name, description, authors, manual section).
  270. man_pages = [
  271. ('index', 'readthedocstemplate', u'Read the Docs Template Documentation',
  272. [u'Read the Docs'], 1)
  273. ]
  274. # If true, show URL addresses after external links.
  275. # man_show_urls = False
  276. # -- Options for Texinfo output -------------------------------------------
  277. # Grouping the document tree into Texinfo files. List of tuples
  278. # (source start file, target name, title, author,
  279. # dir menu entry, description, category)
  280. texinfo_documents = [
  281. ('index', 'ReadtheDocsTemplate', u'Read the Docs Template Documentation',
  282. u'Read the Docs', 'ReadtheDocsTemplate', 'One line description of project.',
  283. 'Miscellaneous'),
  284. ]
  285. # Documents to append as an appendix to all manuals.
  286. # texinfo_appendices = []
  287. # If false, no module index is generated.
  288. # texinfo_domain_indices = True
  289. # How to display URL addresses: 'footnote', 'no', or 'inline'.
  290. # texinfo_show_urls = 'footnote'
  291. # If true, do not generate a @detailmenu in the "Top" node's menu.
  292. # texinfo_no_detailmenu = False
  293. # Override RTD CSS theme to introduce the theme corrections
  294. # https://github.com/rtfd/sphinx_rtd_theme/pull/432
  295. def setup(app):
  296. app.add_stylesheet('theme_overrides.css')
  297. # these two must be pushed in by build_docs.py
  298. if "idf_target" not in app.config:
  299. app.add_config_value('idf_target', None, 'env')
  300. app.add_config_value('idf_targets', None, 'env')
  301. app.add_config_value('conditional_include_dict', None, 'env')
  302. app.add_config_value('docs_to_build', None, 'env')
  303. # Breathe extension variables (depend on build_dir)
  304. # note: we generate into xml_in and then copy_if_modified to xml dir
  305. app.config.breathe_projects = {"esp32-idf": os.path.join(app.config.build_dir, "xml_in/")}
  306. app.config.breathe_default_project = "esp32-idf"
  307. setup_diag_font(app)
  308. # Config values pushed by -D using the cmdline is not available when setup is called
  309. app.connect('config-inited', setup_config_values)
  310. app.connect('config-inited', setup_html_context)
  311. def setup_config_values(app, config):
  312. # Sets up global config values needed by other extensions
  313. idf_target_title_dict = {
  314. 'esp32': 'ESP32',
  315. 'esp32s2': 'ESP32-S2'
  316. }
  317. app.add_config_value('idf_target_title_dict', idf_target_title_dict, 'env')
  318. pdf_name = "esp-idf-{}-{}-{}".format(app.config.language, app.config.version, app.config.idf_target)
  319. app.add_config_value('pdf_file', pdf_name, 'env')
  320. def setup_html_context(app, config):
  321. # Setup path for 'edit on github'-link
  322. config.html_context['conf_py_path'] = "/docs/{}/".format(app.config.language)
  323. def setup_diag_font(app):
  324. # blockdiag and other tools require a font which supports their character set
  325. # the font file is stored on the download server to save repo size
  326. font_name = {
  327. 'en': 'DejaVuSans.ttf',
  328. 'zh_CN': 'NotoSansSC-Regular.otf',
  329. }[app.config.language]
  330. font_dir = os.path.join(config_dir, '_static')
  331. assert os.path.exists(font_dir)
  332. print("Downloading font file %s for %s" % (font_name, app.config.language))
  333. download_file_if_missing('https://dl.espressif.com/dl/esp-idf/docs/_static/{}'.format(font_name), font_dir)
  334. font_path = os.path.abspath(os.path.join(font_dir, font_name))
  335. assert os.path.exists(font_path)
  336. app.config.blockdiag_fontpath = font_path
  337. app.config.seqdiag_fontpath = font_path
  338. app.config.actdiag_fontpath = font_path
  339. app.config.nwdiag_fontpath = font_path
  340. app.config.rackdiag_fontpath = font_path
  341. app.config.packetdiag_fontpath = font_path