conf.py 9.8 KB

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