conf.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Godot Engine documentation build configuration file
  4. import sphinx_rtd_theme
  5. import sys
  6. import os
  7. # -- General configuration ------------------------------------------------
  8. needs_sphinx = "1.3"
  9. # Sphinx extension module names and templates location
  10. sys.path.append(os.path.abspath("_extensions"))
  11. extensions = [
  12. "sphinx_tabs.tabs",
  13. "notfound.extension",
  14. "sphinxext.opengraph",
  15. ]
  16. # Warning when the Sphinx Tabs extension is used with unknown
  17. # builders (like the dummy builder) - as it doesn't cause errors,
  18. # we can ignore this so we still can treat other warnings as errors.
  19. sphinx_tabs_nowarn = True
  20. # Custom 4O4 page HTML template.
  21. # https://github.com/readthedocs/sphinx-notfound-page
  22. notfound_context = {
  23. "title": "Page not found",
  24. "body": """
  25. <h1>Page not found</h1>
  26. <p>
  27. Sorry, we couldn't find that page. It may have been renamed or removed
  28. in the version of the documentation you're currently browsing.
  29. </p>
  30. <p>
  31. If you're currently browsing the
  32. <em>stable</em> version of the documentation, try browsing the
  33. <a href="/en/latest/"><em>latest</em> version of the documentation</a>.
  34. </p>
  35. <p>
  36. Alternatively, use the
  37. <a href="#" onclick="$('#rtd-search-form [name=\\'q\\']').focus()">Search docs</a>
  38. box on the left or <a href="/">go to the homepage</a>.
  39. </p>
  40. """,
  41. }
  42. # on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
  43. on_rtd = os.environ.get("READTHEDOCS", None) == "True"
  44. # Don't add `/en/latest` prefix during local development.
  45. # This makes it easier to test the custom 404 page by loading `/404.html`
  46. # on a local web server.
  47. if not on_rtd:
  48. notfound_urls_prefix = ''
  49. # Specify the site name for the Open Graph extension.
  50. ogp_site_name = "Godot Engine documentation"
  51. if not os.getenv("SPHINX_NO_GDSCRIPT"):
  52. extensions.append("gdscript")
  53. if not os.getenv("SPHINX_NO_DESCRIPTIONS"):
  54. extensions.append("godot_descriptions")
  55. templates_path = ["_templates"]
  56. # You can specify multiple suffix as a list of string: ['.rst', '.md']
  57. source_suffix = ".rst"
  58. source_encoding = "utf-8-sig"
  59. # The master toctree document
  60. master_doc = "index"
  61. # General information about the project
  62. project = "Godot Engine"
  63. copyright = (
  64. "2014-2021, Juan Linietsky, Ariel Manzur and the Godot community (CC-BY 3.0)"
  65. )
  66. author = "Juan Linietsky, Ariel Manzur and the Godot community"
  67. # Version info for the project, acts as replacement for |version| and |release|
  68. # The short X.Y version
  69. version = os.getenv("READTHEDOCS_VERSION", "3.2")
  70. # The full version, including alpha/beta/rc tags
  71. release = version
  72. # Parse Sphinx tags passed from RTD via environment
  73. env_tags = os.getenv("SPHINX_TAGS")
  74. if env_tags is not None:
  75. for tag in env_tags.split(","):
  76. print("Adding Sphinx tag: %s" % tag.strip())
  77. tags.add(tag.strip()) # noqa: F821
  78. # Language / i18n
  79. supported_languages = {
  80. "en": "Godot Engine (%s) documentation in English",
  81. "de": "Godot Engine (%s) Dokumentation auf Deutsch",
  82. "es": "Documentación de Godot Engine (%s) en español",
  83. "fr": "Documentation de Godot Engine (%s) en français",
  84. "fi": "Godot Engine (%s) dokumentaatio suomeksi",
  85. "it": "Godot Engine (%s) documentazione in italiano",
  86. "ja": "Godot Engine (%s)の日本語のドキュメント",
  87. "ko": "Godot Engine (%s) 문서 (한국어)",
  88. "pl": "Dokumentacja Godot Engine (%s) w języku polskim",
  89. "pt_BR": "Documentação da Godot Engine (%s) em Português Brasileiro",
  90. "ru": "Документация Godot Engine (%s) на русском языке",
  91. "uk": "Документація до Godot Engine (%s) українською мовою",
  92. "zh_CN": "Godot Engine (%s) 简体中文文档",
  93. "zh_TW": "Godot Engine (%s) 正體中文 (台灣) 文件",
  94. }
  95. language = os.getenv("READTHEDOCS_LANGUAGE", "en")
  96. if not language in supported_languages.keys():
  97. print("Unknown language: " + language)
  98. print("Supported languages: " + ", ".join(supported_languages.keys()))
  99. print(
  100. "The configured language is either wrong, or it should be added to supported_languages in conf.py. Falling back to 'en'."
  101. )
  102. language = "en"
  103. is_i18n = tags.has("i18n") # noqa: F821
  104. exclude_patterns = ["_build"]
  105. # fmt: off
  106. # These imports should *not* be moved to the start of the file,
  107. # they depend on the sys.path.append call registering "_extensions".
  108. # GDScript syntax highlighting
  109. from gdscript import GDScriptLexer
  110. from sphinx.highlighting import lexers
  111. lexers["gdscript"] = GDScriptLexer()
  112. # fmt: on
  113. smartquotes = False
  114. # Pygments (syntax highlighting) style to use
  115. pygments_style = "sphinx"
  116. highlight_language = "gdscript"
  117. # -- Options for HTML output ----------------------------------------------
  118. html_theme = "sphinx_rtd_theme"
  119. html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
  120. if on_rtd:
  121. using_rtd_theme = True
  122. # Theme options
  123. html_theme_options = {
  124. # if we have a html_logo below, this shows /only/ the logo with no title text
  125. "logo_only": True,
  126. # Collapse navigation (False makes it tree-like)
  127. "collapse_navigation": False,
  128. }
  129. html_title = supported_languages[language] % version
  130. # VCS options: https://docs.readthedocs.io/en/latest/vcs.html#github
  131. html_context = {
  132. "display_github": not is_i18n, # Integrate GitHub
  133. "github_user": "godotengine", # Username
  134. "github_repo": "godot-docs", # Repo name
  135. "github_version": "master", # Version
  136. "conf_py_path": "/", # Path in the checkout to the docs root
  137. "godot_inject_language_links": True,
  138. "godot_docs_supported_languages": list(supported_languages.keys()),
  139. "godot_docs_basepath": "https://docs.godotengine.org/",
  140. "godot_docs_suffix": ".html",
  141. "godot_default_lang": "en",
  142. "godot_canonical_version": "stable",
  143. # Distinguish local development website from production website.
  144. # This prevents people from looking for changes on the production website after making local changes :)
  145. "godot_title_prefix": "" if on_rtd else "(DEV) ",
  146. }
  147. html_logo = "img/docs_logo.png"
  148. # These folders are copied to the documentation's HTML output
  149. html_static_path = ["_static"]
  150. html_extra_path = ["robots.txt"]
  151. # These paths are either relative to html_static_path
  152. # or fully qualified paths (eg. https://...)
  153. html_css_files = [
  154. "css/custom.css",
  155. ]
  156. html_js_files = [
  157. "js/custom.js",
  158. ]
  159. # Output file base name for HTML help builder
  160. htmlhelp_basename = "GodotEnginedoc"
  161. # -- Options for reStructuredText parser ----------------------------------
  162. # Enable directives that insert the contents of external files
  163. file_insertion_enabled = False
  164. # -- Options for LaTeX output ---------------------------------------------
  165. # Grouping the document tree into LaTeX files. List of tuples
  166. # (source start file, target name, title,
  167. # author, documentclass [howto, manual, or own class]).
  168. latex_documents = [
  169. (
  170. master_doc,
  171. "GodotEngine.tex",
  172. "Godot Engine Documentation",
  173. "Juan Linietsky, Ariel Manzur and the Godot community",
  174. "manual",
  175. ),
  176. ]
  177. # -- Options for linkcheck builder ----------------------------------------
  178. # disable checking urls with about.html#this_part_of_page anchors
  179. linkcheck_anchors = False
  180. linkcheck_timeout = 10
  181. # -- I18n settings --------------------------------------------------------
  182. # Godot localization is handled via https://github.com/godotengine/godot-docs-l10n
  183. # where the main docs repo is a submodule. Therefore the translated material is
  184. # actually in the parent folder of this conf.py, hence the "../".
  185. locale_dirs = ["../sphinx/po/"]
  186. gettext_compact = False
  187. # We want to host the localized images in godot-docs-l10n, but Sphinx does not provide
  188. # the necessary feature to do so. `figure_language_filename` has `{root}` and `{path}`,
  189. # but they resolve to (host) absolute paths, so we can't use them as is to access "../".
  190. # However, Python is glorious and lets us redefine Sphinx's internal method that handles
  191. # `figure_language_filename`, so we do our own post-processing to fix the absolute path
  192. # and point to the parallel folder structure in godot-docs-l10n.
  193. # Note: Sphinx's handling of `figure_language_filename` may change in the future, monitor
  194. # https://github.com/sphinx-doc/sphinx/issues/7768 to see what would be relevant for us.
  195. figure_language_filename = "{root}.{language}{ext}"
  196. import sphinx
  197. cwd = os.getcwd()
  198. sphinx_original_get_image_filename_for_language = sphinx.util.i18n.get_image_filename_for_language
  199. def godot_get_image_filename_for_language(filename, env):
  200. """
  201. Hack the absolute path returned by Sphinx based on `figure_language_filename`
  202. to insert our `../images` relative path to godot-docs-l10n's images folder,
  203. which mirrors the folder structure of the docs repository.
  204. The returned string should also be absolute so that `os.path.exists` can properly
  205. resolve it when trying to concatenate with the original doc folder.
  206. """
  207. path = sphinx_original_get_image_filename_for_language(filename, env)
  208. path = os.path.abspath(os.path.join("../images/", os.path.relpath(path, cwd)))
  209. return path
  210. sphinx.util.i18n.get_image_filename_for_language = godot_get_image_filename_for_language