conf.py 9.6 KB

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