conf.py 8.8 KB

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