conf_common.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 re
  21. import subprocess
  22. from sanitize_version import sanitize_version
  23. from get_github_rev import get_github_rev
  24. # Note: If extensions (or modules to document with autodoc) are in another directory,
  25. # add these directories to sys.path here. If the directory is relative to the
  26. # documentation root, use os.path.abspath to make it absolute
  27. from local_util import copy_if_modified
  28. # build_docs on the CI server sometimes fails under Python3. This is a workaround:
  29. sys.setrecursionlimit(3500)
  30. config_dir = os.path.abspath(os.path.dirname(__file__))
  31. try:
  32. builddir = os.environ['BUILDDIR']
  33. except KeyError:
  34. builddir = '_build'
  35. # Fill in a default IDF_PATH if it's missing (ie when Read The Docs is building the docs)
  36. try:
  37. idf_path = os.environ['IDF_PATH']
  38. except KeyError:
  39. idf_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
  40. def call_with_python(cmd):
  41. # using sys.executable ensures that the scripts are called with the same Python interpreter
  42. if os.system('{} {}'.format(sys.executable, cmd)) != 0:
  43. raise RuntimeError('{} failed'.format(cmd))
  44. # Call Doxygen to get XML files from the header files
  45. print("Calling Doxygen to generate latest XML files")
  46. if os.system("doxygen ../Doxyfile") != 0:
  47. raise RuntimeError('Doxygen call failed')
  48. # Doxygen has generated XML files in 'xml' directory.
  49. # Copy them to 'xml_in', only touching the files which have changed.
  50. copy_if_modified('xml/', 'xml_in/')
  51. # Generate 'api_name.inc' files using the XML files by Doxygen
  52. call_with_python('../gen-dxd.py')
  53. def find_component_files(parent_dir, target_filename):
  54. parent_dir = os.path.abspath(parent_dir)
  55. result = []
  56. component_files = dict()
  57. for (dirpath, dirnames, filenames) in os.walk(parent_dir):
  58. try:
  59. # note: trimming "examples" dir as MQTT submodule
  60. # has its own examples directory in the submodule, not part of IDF
  61. dirnames.remove("examples")
  62. except ValueError:
  63. pass
  64. if target_filename in filenames:
  65. component_files[os.path.basename(dirpath)] = os.path.join(dirpath, target_filename)
  66. components = sorted(component_files.keys())
  67. for component in components:
  68. result.append(component_files[component])
  69. print("List of %s: %s" % (target_filename, ", ".join(components)))
  70. return result
  71. # Generate 'kconfig.inc' file from components' Kconfig files
  72. print("Generating kconfig.inc from kconfig contents")
  73. kconfig_inc_path = '{}/inc/kconfig.inc'.format(builddir)
  74. temp_sdkconfig_path = '{}/sdkconfig.tmp'.format(builddir)
  75. kconfigs = find_component_files("../../components", "Kconfig")
  76. kconfig_projbuilds = find_component_files("../../components", "Kconfig.projbuild")
  77. sdkconfig_renames = find_component_files("../../components", "sdkconfig.rename")
  78. # trim the esp32s2beta component, until we have proper multi-target support
  79. kconfigs = [k for k in kconfigs if "esp32s2beta" not in k]
  80. kconfig_projbuilds = [k for k in kconfig_projbuilds if "esp32s2beta" not in k]
  81. sdkconfig_renames = [r for r in sdkconfig_renames if "esp32s2beta" not in r]
  82. kconfigs_source_path = '{}/inc/kconfigs_source.in'.format(builddir)
  83. kconfig_projbuilds_source_path = '{}/inc/kconfig_projbuilds_source.in'.format(builddir)
  84. prepare_kconfig_files_args = [sys.executable,
  85. "../../tools/kconfig_new/prepare_kconfig_files.py",
  86. "--env", "COMPONENT_KCONFIGS={}".format(" ".join(kconfigs)),
  87. "--env", "COMPONENT_KCONFIGS_PROJBUILD={}".format(" ".join(kconfig_projbuilds)),
  88. "--env", "COMPONENT_KCONFIGS_SOURCE_FILE={}".format(kconfigs_source_path),
  89. "--env", "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE={}".format(kconfig_projbuilds_source_path),
  90. ]
  91. subprocess.check_call(prepare_kconfig_files_args)
  92. confgen_args = [sys.executable,
  93. "../../tools/kconfig_new/confgen.py",
  94. "--kconfig", "../../Kconfig",
  95. "--sdkconfig-rename", "../../sdkconfig.rename",
  96. "--config", temp_sdkconfig_path,
  97. "--env", "COMPONENT_KCONFIGS={}".format(" ".join(kconfigs)),
  98. "--env", "COMPONENT_KCONFIGS_PROJBUILD={}".format(" ".join(kconfig_projbuilds)),
  99. "--env", "COMPONENT_SDKCONFIG_RENAMES={}".format(" ".join(sdkconfig_renames)),
  100. "--env", "COMPONENT_KCONFIGS_SOURCE_FILE={}".format(kconfigs_source_path),
  101. "--env", "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE={}".format(kconfig_projbuilds_source_path),
  102. "--env", "IDF_PATH={}".format(idf_path),
  103. "--output", "docs", kconfig_inc_path + '.in'
  104. ]
  105. subprocess.check_call(confgen_args)
  106. copy_if_modified(kconfig_inc_path + '.in', kconfig_inc_path)
  107. # Generate 'esp_err_defs.inc' file with ESP_ERR_ error code definitions
  108. esp_err_inc_path = '{}/inc/esp_err_defs.inc'.format(builddir)
  109. call_with_python('../../tools/gen_esp_err_to_name.py --rst_output ' + esp_err_inc_path + '.in')
  110. copy_if_modified(esp_err_inc_path + '.in', esp_err_inc_path)
  111. # Generate version-related includes
  112. #
  113. # (Note: this is in a function as it needs to access configuration to get the language)
  114. def generate_version_specific_includes(app):
  115. print("Generating version-specific includes...")
  116. version_tmpdir = '{}/version_inc'.format(builddir)
  117. call_with_python('../gen-version-specific-includes.py {} {}'.format(app.config.language, version_tmpdir))
  118. copy_if_modified(version_tmpdir, '{}/inc'.format(builddir))
  119. # Generate toolchain download links
  120. print("Generating toolchain download links")
  121. base_url = 'https://dl.espressif.com/dl/'
  122. toolchain_tmpdir = '{}/toolchain_inc'.format(builddir)
  123. call_with_python('../gen-toolchain-links.py ../../tools/toolchain_versions.mk {} {}'.format(base_url, toolchain_tmpdir))
  124. copy_if_modified(toolchain_tmpdir, '{}/inc'.format(builddir))
  125. # http://stackoverflow.com/questions/12772927/specifying-an-online-image-in-sphinx-restructuredtext-format
  126. #
  127. suppress_warnings = ['image.nonlocal_uri']
  128. # -- General configuration ------------------------------------------------
  129. # If your documentation needs a minimal Sphinx version, state it here.
  130. # needs_sphinx = '1.0'
  131. # Add any Sphinx extension module names here, as strings. They can be
  132. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  133. # ones.
  134. extensions = ['breathe',
  135. 'sphinx_idf_theme',
  136. 'link-roles',
  137. 'sphinxcontrib.blockdiag',
  138. 'sphinxcontrib.seqdiag',
  139. 'sphinxcontrib.actdiag',
  140. 'sphinxcontrib.nwdiag',
  141. 'sphinxcontrib.rackdiag',
  142. 'sphinxcontrib.packetdiag',
  143. 'html_redirects',
  144. 'sphinx.ext.todo',
  145. 'latex_builder',
  146. ]
  147. # sphinx.ext.todo extension parameters
  148. # If the below parameter is True, the extension
  149. # produces output, else it produces nothing.
  150. todo_include_todos = False
  151. # Enabling this fixes cropping of blockdiag edge labels
  152. seqdiag_antialias = True
  153. # Breathe extension variables
  154. # Doxygen regenerates files in 'xml/' directory every time,
  155. # but we copy files to 'xml_in/' only when they change, to speed up
  156. # incremental builds.
  157. breathe_projects = {"esp32-idf": "xml_in/"}
  158. breathe_default_project = "esp32-idf"
  159. # Add any paths that contain templates here, relative to this directory.
  160. templates_path = ['_templates']
  161. # The suffix of source filenames.
  162. source_suffix = ['.rst', '.md']
  163. source_parsers = {'.md': 'recommonmark.parser.CommonMarkParser',
  164. }
  165. # The encoding of source files.
  166. # source_encoding = 'utf-8-sig'
  167. # The master toctree document.
  168. master_doc = 'index'
  169. # The version info for the project you're documenting, acts as replacement for
  170. # |version| and |release|, also used in various other places throughout the
  171. # built documents.
  172. #
  173. # This is the full exact version, canonical git version description
  174. # visible when you open index.html.
  175. version = subprocess.check_output(['git', 'describe']).strip().decode('utf-8')
  176. # The 'release' version is the same as version for non-CI builds, but for CI
  177. # builds on a branch then it's replaced with the branch name
  178. release = sanitize_version(version)
  179. print('Version: {0} Release: {1}'.format(version, release))
  180. # There are two options for replacing |today|: either, you set today to some
  181. # non-false value, then it is used:
  182. # today = ''
  183. # Else, today_fmt is used as the format for a strftime call.
  184. # today_fmt = '%B %d, %Y'
  185. # List of patterns, relative to source directory, that match files and
  186. # directories to ignore when looking for source files.
  187. exclude_patterns = ['_build','README.md']
  188. # The reST default role (used for this markup: `text`) to use for all
  189. # documents.
  190. # default_role = None
  191. # If true, '()' will be appended to :func: etc. cross-reference text.
  192. # add_function_parentheses = True
  193. # If true, the current module name will be prepended to all description
  194. # unit titles (such as .. function::).
  195. # add_module_names = True
  196. # If true, sectionauthor and moduleauthor directives will be shown in the
  197. # output. They are ignored by default.
  198. # show_authors = False
  199. # The name of the Pygments (syntax highlighting) style to use.
  200. pygments_style = 'sphinx'
  201. # Extra options required by sphinx_idf_theme
  202. project_slug = 'esp-idf'
  203. versions_url = 'https://dl.espressif.com/dl/esp-idf/idf_versions.js'
  204. languages = ['en', 'zh_CN']
  205. # A list of ignored prefixes for module index sorting.
  206. # modindex_common_prefix = []
  207. # If true, keep warnings as "system message" paragraphs in the built documents.
  208. # keep_warnings = False
  209. # -- Options for HTML output ----------------------------------------------
  210. # Custom added feature to allow redirecting old URLs
  211. #
  212. # Redirects should be listed in page_redirects.xt
  213. #
  214. with open("../page_redirects.txt") as f:
  215. lines = [re.sub(" +", " ", line.strip()) for line in f.readlines() if line.strip() != "" and not line.startswith("#")]
  216. for line in lines: # check for well-formed entries
  217. if len(line.split(' ')) != 2:
  218. raise RuntimeError("Invalid line in page_redirects.txt: %s" % line)
  219. html_redirect_pages = [tuple(line.split(' ')) for line in lines]
  220. # The theme to use for HTML and HTML Help pages. See the documentation for
  221. # a list of builtin themes.
  222. html_theme = 'sphinx_idf_theme'
  223. # context used by sphinx_idf_theme
  224. html_context = {
  225. "display_github": True, # Add 'Edit on Github' link instead of 'View page source'
  226. "github_user": "espressif",
  227. "github_repo": "esp-idf",
  228. "github_version": get_github_rev(),
  229. }
  230. # Theme options are theme-specific and customize the look and feel of a theme
  231. # further. For a list of options available for each theme, see the
  232. # documentation.
  233. # html_theme_options = {}
  234. # Add any paths that contain custom themes here, relative to this directory.
  235. # html_theme_path = []
  236. # The name for this set of Sphinx documents. If None, it defaults to
  237. # "<project> v<release> documentation".
  238. # html_title = None
  239. # A shorter title for the navigation bar. Default is the same as html_title.
  240. # html_short_title = None
  241. # The name of an image file (relative to this directory) to place at the top
  242. # of the sidebar.
  243. html_logo = "../_static/espressif-logo.svg"
  244. # The name of an image file (within the static path) to use as favicon of the
  245. # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
  246. # pixels large.
  247. # html_favicon = None
  248. # Add any paths that contain custom static files (such as style sheets) here,
  249. # relative to this directory. They are copied after the builtin static files,
  250. # so a file named "default.css" will overwrite the builtin "default.css".
  251. html_static_path = ['../_static']
  252. # Add any extra paths that contain custom files (such as robots.txt or
  253. # .htaccess) here, relative to this directory. These files are copied
  254. # directly to the root of the documentation.
  255. # html_extra_path = []
  256. # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
  257. # using the given strftime format.
  258. # html_last_updated_fmt = '%b %d, %Y'
  259. # If true, SmartyPants will be used to convert quotes and dashes to
  260. # typographically correct entities.
  261. # html_use_smartypants = True
  262. # Custom sidebar templates, maps document names to template names.
  263. # html_sidebars = {}
  264. # Additional templates that should be rendered to pages, maps page names to
  265. # template names.
  266. # html_additional_pages = {}
  267. # If false, no module index is generated.
  268. # html_domain_indices = True
  269. # If false, no index is generated.
  270. # html_use_index = True
  271. # If true, the index is split into individual pages for each letter.
  272. # html_split_index = False
  273. # If true, links to the reST sources are added to the pages.
  274. # html_show_sourcelink = True
  275. # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
  276. # html_show_sphinx = True
  277. # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
  278. # html_show_copyright = True
  279. # If true, an OpenSearch description file will be output, and all pages will
  280. # contain a <link> tag referring to it. The value of this option must be the
  281. # base URL from which the finished HTML is served.
  282. # html_use_opensearch = ''
  283. # This is the file name suffix for HTML files (e.g. ".xhtml").
  284. # html_file_suffix = None
  285. # Output file base name for HTML help builder.
  286. htmlhelp_basename = 'ReadtheDocsTemplatedoc'
  287. # -- Options for LaTeX output ---------------------------------------------
  288. latex_template_dir = os.path.join(config_dir, 'latex_templates')
  289. preamble = ''
  290. with open(os.path.join(latex_template_dir, 'preamble.tex')) as f:
  291. preamble = f.read()
  292. titlepage = ''
  293. with open(os.path.join(latex_template_dir, 'titlepage.tex')) as f:
  294. titlepage = f.read()
  295. latex_elements = {
  296. 'papersize': 'a4paper',
  297. # Latex figure (float) alignment
  298. 'figure_align':'htbp',
  299. 'pointsize': '10pt',
  300. # Additional stuff for the LaTeX preamble.
  301. 'fncychap': '\\usepackage[Sonny]{fncychap}',
  302. 'preamble': preamble,
  303. 'maketitle': titlepage,
  304. }
  305. # The name of an image file (relative to this directory) to place at the top of
  306. # the title page.
  307. # The name of an image file (relative to this directory) to place at the bottom of
  308. # the title page.
  309. latex_logo = "../_static/espressif2.pdf"
  310. latex_engine = 'xelatex'
  311. latex_use_xindy = False
  312. # For "manual" documents, if this is true, then toplevel headings are parts,
  313. # not chapters.
  314. # latex_use_parts = False
  315. # If true, show page references after internal links.
  316. # latex_show_pagerefs = False
  317. # If true, show URL addresses after external links.
  318. # latex_show_urls = False
  319. # Documents to append as an appendix to all manuals.
  320. # latex_appendices = []
  321. # If false, no module index is generated.
  322. # latex_domain_indices = True
  323. # -- Options for manual page output ---------------------------------------
  324. # One entry per manual page. List of tuples
  325. # (source start file, name, description, authors, manual section).
  326. man_pages = [
  327. ('index', 'readthedocstemplate', u'Read the Docs Template Documentation',
  328. [u'Read the Docs'], 1)
  329. ]
  330. # If true, show URL addresses after external links.
  331. # man_show_urls = False
  332. # -- Options for Texinfo output -------------------------------------------
  333. # Grouping the document tree into Texinfo files. List of tuples
  334. # (source start file, target name, title, author,
  335. # dir menu entry, description, category)
  336. texinfo_documents = [
  337. ('index', 'ReadtheDocsTemplate', u'Read the Docs Template Documentation',
  338. u'Read the Docs', 'ReadtheDocsTemplate', 'One line description of project.',
  339. 'Miscellaneous'),
  340. ]
  341. # Documents to append as an appendix to all manuals.
  342. # texinfo_appendices = []
  343. # If false, no module index is generated.
  344. # texinfo_domain_indices = True
  345. # How to display URL addresses: 'footnote', 'no', or 'inline'.
  346. # texinfo_show_urls = 'footnote'
  347. # If true, do not generate a @detailmenu in the "Top" node's menu.
  348. # texinfo_no_detailmenu = False
  349. # Override RTD CSS theme to introduce the theme corrections
  350. # https://github.com/rtfd/sphinx_rtd_theme/pull/432
  351. def setup(app):
  352. app.add_stylesheet('theme_overrides.css')
  353. generate_version_specific_includes(app)
  354. # Not all config variables are set when setup is called
  355. app.connect('config-inited', setup_config_values)
  356. app.connect('config-inited', setup_html_context)
  357. def setup_config_values(app, config):
  358. # Sets up global config values needed by other extensions
  359. idf_target_title_dict = {
  360. 'esp32': 'ESP32',
  361. 'esp32s2': 'ESP32-S2'
  362. }
  363. app.add_config_value('idf_target_title_dict', idf_target_title_dict, 'env')
  364. pdf_name = "esp-idf-{}-{}-{}".format(app.config.language, app.config.version, "esp32")
  365. app.add_config_value('pdf_file', pdf_name, 'env')
  366. def setup_html_context(app, config):
  367. # Setup path for 'edit on github'-link
  368. app.config.html_context['conf_py_path'] = "/docs/{}/".format(app.config.language)