conf.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Godot Engine documentation build configuration file
  4. import sphinx
  5. import sphinx_rtd_theme
  6. import sys
  7. import os
  8. # -- General configuration ------------------------------------------------
  9. needs_sphinx = "8.1"
  10. # Sphinx extension module names and templates location
  11. sys.path.append(os.path.abspath("_extensions"))
  12. extensions = [
  13. "sphinx_tabs.tabs",
  14. "notfound.extension",
  15. "sphinxext.opengraph",
  16. "sphinx_copybutton",
  17. "sphinxcontrib.video",
  18. "gdscript",
  19. ]
  20. # Warning when the Sphinx Tabs extension is used with unknown
  21. # builders (like the dummy builder) - as it doesn't cause errors,
  22. # we can ignore this so we still can treat other warnings as errors.
  23. sphinx_tabs_nowarn = True
  24. # Disable collapsing tabs for codeblocks.
  25. sphinx_tabs_disable_tab_closing = True
  26. # on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
  27. on_rtd = os.environ.get("READTHEDOCS", None) == "True"
  28. # Don't add `/en/latest` prefix during local development.
  29. # This makes it easier to test the custom 404 page by loading `/404.html`
  30. # on a local web server.
  31. if not on_rtd:
  32. notfound_urls_prefix = ''
  33. if on_rtd:
  34. extensions.append("override_jobs")
  35. # Specify the site name for the Open Graph extension.
  36. ogp_site_name = "Godot Engine documentation"
  37. ogp_social_cards = {
  38. "enable": False
  39. }
  40. if not os.getenv("SPHINX_NO_DESCRIPTIONS"):
  41. extensions.append("godot_descriptions")
  42. templates_path = ["_templates"]
  43. # You can specify multiple suffix as a list of string: ['.rst', '.md']
  44. source_suffix = ".rst"
  45. source_encoding = "utf-8-sig"
  46. # The master toctree document
  47. master_doc = "index"
  48. # General information about the project
  49. project = "Godot Engine"
  50. copyright = (
  51. "2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0)"
  52. )
  53. author = "Juan Linietsky, Ariel Manzur and the Godot community"
  54. # Version info for the project, acts as replacement for |version| and |release|
  55. # The short X.Y version
  56. version = os.getenv("READTHEDOCS_VERSION", "4.6")
  57. # The full version, including alpha/beta/rc tags
  58. release = version
  59. # Parse Sphinx tags passed from RTD via environment
  60. env_tags = os.getenv("SPHINX_TAGS")
  61. if env_tags is not None:
  62. for tag in env_tags.split(","):
  63. print("Adding Sphinx tag: %s" % tag.strip())
  64. tags.add(tag.strip()) # noqa: F821
  65. # Language / i18n
  66. supported_languages = {
  67. "en": "Godot Engine %s documentation in English",
  68. "de": "Godot Engine %s Dokumentation auf Deutsch",
  69. "es": "Documentación de Godot Engine %s en español",
  70. "fr": "Documentation de Godot Engine %s en français",
  71. "fi": "Godot Engine %s dokumentaatio suomeksi",
  72. "it": "Godot Engine %s documentazione in italiano",
  73. "ja": "Godot Engine %sの日本語のドキュメント",
  74. "ko": "Godot Engine %s 문서 (한국어)",
  75. "pl": "Dokumentacja Godot Engine %s w języku polskim",
  76. "pt_BR": "Documentação da Godot Engine %s em Português Brasileiro",
  77. "ru": "Документация Godot Engine %s на русском языке",
  78. "uk": "Документація до Godot Engine %s українською мовою",
  79. "zh_Hans": "Godot Engine %s 简体中文文档",
  80. "zh_Hant": "Godot Engine %s 正體中文 (台灣) 文件",
  81. # Keeping those as RTD doesn't support Hans/Hant names yet.
  82. "zh_CN": "Godot Engine %s 简体中文文档",
  83. "zh_TW": "Godot Engine %s 正體中文 (台灣) 文件",
  84. }
  85. # RTD normalized their language codes to ll-cc (e.g. pt-br),
  86. # but Sphinx did not and still uses ll_CC (e.g. pt_BR).
  87. # `language` is the Sphinx configuration so it needs to be converted back.
  88. language = os.getenv("READTHEDOCS_LANGUAGE", "en")
  89. if "-" in language:
  90. (lang_name, lang_country) = language.split("-")
  91. language = lang_name + "_" + lang_country.upper()
  92. if not language in supported_languages.keys():
  93. print("Unknown language: " + language)
  94. print("Supported languages: " + ", ".join(supported_languages.keys()))
  95. print(
  96. "The configured language is either wrong, or it should be added to supported_languages in conf.py. Falling back to 'en'."
  97. )
  98. language = "en"
  99. is_i18n = tags.has("i18n") # noqa: F821
  100. print("Build language: {}, i18n tag: {}".format(language, is_i18n))
  101. exclude_patterns = [".*", "**/.*", "_build", "_tools"]
  102. smartquotes = False
  103. # Pygments (syntax highlighting) style to use
  104. pygments_style = "sphinx"
  105. highlight_language = "gdscript"
  106. # -- Options for HTML output ----------------------------------------------
  107. html_theme = "sphinx_rtd_theme"
  108. if on_rtd:
  109. using_rtd_theme = True
  110. # Theme options
  111. html_theme_options = {
  112. # if we have a html_logo below, this shows /only/ the logo with no title text
  113. "logo_only": True,
  114. # Collapse navigation (False makes it tree-like)
  115. "collapse_navigation": False,
  116. # Remove version and language picker beneath the title
  117. "version_selector": False,
  118. "language_selector": False,
  119. # Set Flyout menu to attached
  120. "flyout_display": "attached",
  121. }
  122. html_title = supported_languages[language] % ( "(" + version + ")" )
  123. # Edit on GitHub options: https://docs.readthedocs.io/en/latest/guides/edit-source-links-sphinx.html
  124. html_context = {
  125. "display_github": not is_i18n, # Integrate GitHub
  126. "github_user": "godotengine", # Username
  127. "github_repo": "godot-docs", # Repo name
  128. "github_version": "master", # Version
  129. "conf_py_path": "/", # Path in the checkout to the docs root
  130. "godot_docs_title": supported_languages[language],
  131. "godot_docs_basepath": "https://docs.godotengine.org/",
  132. "godot_docs_suffix": ".html",
  133. # Distinguish local development website from production website.
  134. # This prevents people from looking for changes on the production website after making local changes :)
  135. "godot_title_prefix": "" if on_rtd else "(DEV) ",
  136. # Set this to `True` when in the `latest` branch to clearly indicate to the reader
  137. # that they are not reading the `stable` documentation.
  138. "godot_is_latest": False,
  139. "godot_version": "4.6",
  140. # Enables a banner that displays the up-to-date status of each article.
  141. "godot_show_article_status": True,
  142. # Display user-contributed notes at the bottom of pages that don't have `:allow_comments: False` at the top.
  143. "godot_show_article_comments": on_rtd and not is_i18n,
  144. }
  145. html_logo = "img/docs_logo.svg"
  146. # These folders are copied to the documentation's HTML output
  147. html_static_path = ["_static"]
  148. html_extra_path = ["robots.txt"]
  149. # These paths are either relative to html_static_path
  150. # or fully qualified paths (e.g. https://...)
  151. html_css_files = [
  152. "css/custom.css",
  153. ]
  154. if not on_rtd:
  155. html_css_files.append("css/dev.css")
  156. html_js_files = [
  157. "js/custom.js",
  158. ('https://plausible.godot.foundation/js/script.file-downloads.outbound-links.js',
  159. {'defer': 'defer', 'data-domain': 'godotengine.org'}),
  160. ]
  161. # Output file base name for HTML help builder
  162. htmlhelp_basename = "GodotEnginedoc"
  163. # -- Options for reStructuredText parser ----------------------------------
  164. # Enable directives that insert the contents of external files
  165. file_insertion_enabled = False
  166. # -- Options for LaTeX output ---------------------------------------------
  167. # Grouping the document tree into LaTeX files. List of tuples
  168. # (source start file, target name, title,
  169. # author, documentclass [howto, manual, or own class]).
  170. latex_documents = [
  171. (
  172. master_doc,
  173. "GodotEngine.tex",
  174. "Godot Engine Documentation",
  175. "Juan Linietsky, Ariel Manzur and the Godot community",
  176. "manual",
  177. ),
  178. ]
  179. # -- Options for linkcheck builder ----------------------------------------
  180. # disable checking urls with about.html#this_part_of_page anchors
  181. linkcheck_anchors = False
  182. linkcheck_timeout = 10
  183. # -- Custom Sphinx roles for UI -------------------------------------------
  184. rst_prolog = """
  185. .. role:: button
  186. :class: role-button role-ui
  187. .. role:: menu
  188. :class: role-menu role-ui
  189. .. role:: inspector
  190. :class: role-ui
  191. .. role:: ui
  192. :class: role-ui
  193. """
  194. # -- I18n settings --------------------------------------------------------
  195. # Godot localization is handled via https://github.com/godotengine/godot-docs-l10n
  196. # where the main docs repo is a submodule. Therefore the translated material is
  197. # actually in the parent folder of this conf.py, hence the "../".
  198. locale_dirs = ["../sphinx/po/"]
  199. gettext_compact = False
  200. # We want to host the localized images in godot-docs-l10n, but Sphinx does not provide
  201. # the necessary feature to do so. `figure_language_filename` has `{root}` and `{path}`,
  202. # but they resolve to (host) absolute paths, so we can't use them as is to access "../".
  203. # However, Python is glorious and lets us redefine Sphinx's internal method that handles
  204. # `figure_language_filename`, so we do our own post-processing to fix the absolute path
  205. # and point to the parallel folder structure in godot-docs-l10n.
  206. # Note: Sphinx's handling of `figure_language_filename` may change in the future, monitor
  207. # https://github.com/sphinx-doc/sphinx/issues/7768 to see what would be relevant for us.
  208. figure_language_filename = "{root}.{language}{ext}"
  209. cwd = os.getcwd()
  210. sphinx_original_get_image_filename_for_language = sphinx.util.i18n.get_image_filename_for_language
  211. def godot_get_image_filename_for_language(filename, env):
  212. """
  213. Hack the absolute path returned by Sphinx based on `figure_language_filename`
  214. to insert our `../images` relative path to godot-docs-l10n's images folder,
  215. which mirrors the folder structure of the docs repository.
  216. The returned string should also be absolute so that `os.path.exists` can properly
  217. resolve it when trying to concatenate with the original doc folder.
  218. """
  219. path = sphinx_original_get_image_filename_for_language(filename, env)
  220. path = os.path.abspath(os.path.join("../images/", os.path.relpath(path, cwd)))
  221. return path
  222. sphinx.util.i18n.get_image_filename_for_language = godot_get_image_filename_for_language
  223. # Similar story for the localized class reference, it's out of tree and there doesn't
  224. # seem to be an easy way for us to tweak the toctree to take this into account.
  225. # So we're deleting the existing class reference and adding a symlink instead...
  226. if is_i18n and os.path.exists("../classes/" + language):
  227. import shutil
  228. if os.path.islink("classes"): # Previously made symlink.
  229. os.unlink("classes")
  230. else:
  231. shutil.rmtree("classes")
  232. os.symlink("../classes/" + language, "classes")
  233. # Couldn't find a way to retrieve variables nor do advanced string
  234. # concat from reST, so had to hardcode this in the "epilog" added to
  235. # all pages. This is used in index.rst to display the Weblate badge.
  236. # On English pages, the badge points to the language-neutral engage page.
  237. rst_epilog = """
  238. .. |weblate_widget| image:: https://hosted.weblate.org/widgets/godot-engine/{image_locale}/godot-docs/287x66-white.png
  239. :alt: Translation status
  240. :target: https://hosted.weblate.org/engage/godot-engine{target_locale}/?utm_source=widget
  241. :width: 287
  242. :height: 66
  243. """.format(
  244. image_locale="-" if language == "en" else language,
  245. target_locale="" if language == "en" else "/" + language,
  246. )
  247. # Needed so the table of contents is created for EPUB
  248. epub_tocscope = 'includehidden'