conf_common.py 16 KB

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