conf_common.py 18 KB

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