conf.py 12 KB

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