conf.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. # -*- coding: utf-8 -*-
  2. import json
  3. from pathlib import Path
  4. from importlib import import_module
  5. import os
  6. import sys
  7. from jinja2.filters import FILTERS
  8. sys.path.insert(0, os.path.abspath("."))
  9. from custom_directives import *
  10. from datetime import datetime
  11. # Mocking modules allows Sphinx to work without installing Ray.
  12. mock_modules()
  13. assert (
  14. "ray" not in sys.modules
  15. ), "If ray is already imported, we will not render documentation correctly!"
  16. # If extensions (or modules to document with autodoc) are in another directory,
  17. # add these directories to sys.path here. If the directory is relative to the
  18. # documentation root, use os.path.abspath to make it absolute, like shown here.
  19. sys.path.insert(0, os.path.abspath("../../python/"))
  20. import ray
  21. # -- General configuration ------------------------------------------------
  22. # The name of a reST role (builtin or Sphinx extension) to use as the default role, that
  23. # is, for text marked up `like this`. This can be set to 'py:obj' to make `filter` a
  24. # cross-reference to the Python function “filter”. The default is None, which doesn’t
  25. # reassign the default role.
  26. default_role = "py:obj"
  27. sys.path.append(os.path.abspath("./_ext"))
  28. extensions = [
  29. "callouts", # custom extension from _ext folder
  30. "sphinx.ext.autodoc",
  31. "sphinx.ext.viewcode",
  32. "sphinx.ext.napoleon",
  33. "sphinx_click.ext",
  34. "sphinx-jsonschema",
  35. "sphinxemoji.sphinxemoji",
  36. "sphinx_copybutton",
  37. "versionwarning.extension",
  38. "sphinx_sitemap",
  39. "myst_nb",
  40. "sphinx.ext.doctest",
  41. "sphinx.ext.coverage",
  42. "sphinx.ext.autosummary",
  43. "sphinx_external_toc",
  44. "sphinxcontrib.autodoc_pydantic",
  45. "sphinxcontrib.redoc",
  46. "sphinx_tabs.tabs",
  47. "sphinx_remove_toctrees",
  48. "sphinx_design",
  49. ]
  50. # Prune deep toc-trees on demand for smaller html and faster builds.
  51. # This only effects the navigation bar, not the content.
  52. if os.getenv("FAST", False):
  53. remove_from_toctrees = [
  54. "data/api/doc/*",
  55. "ray-air/api/doc/*",
  56. "ray-core/api/doc/*",
  57. "ray-observability/api/state/doc/*",
  58. "serve/api/doc/*",
  59. "train/api/doc/*",
  60. "tune/api/doc/*",
  61. "workflows/api/doc/*",
  62. "cluster/running-applications/job-submission/doc/*",
  63. "serve/production-guide/*",
  64. "serve/tutorials/deployment-graph-patterns/*",
  65. "rllib/package_ref/env/*",
  66. "rllib/package_ref/policy/*",
  67. "rllib/package_ref/evaluation/*",
  68. "rllib/package_ref/utils/*",
  69. "workflows/api/*",
  70. "cluster/kubernetes/user-guides/*",
  71. "cluster/kubernetes/examples/*",
  72. "cluster/vms/user-guides/*",
  73. "cluster/running-applications/job-submission/*",
  74. "ray-core/actors/*",
  75. "ray-core/objects/*",
  76. "ray-core/scheduling/*",
  77. "ray-core/tasks/*",
  78. "ray-core/patterns/*",
  79. "tune/examples/*",
  80. ]
  81. myst_enable_extensions = [
  82. "dollarmath",
  83. "amsmath",
  84. "deflist",
  85. "html_admonition",
  86. "html_image",
  87. "colon_fence",
  88. "smartquotes",
  89. "replacements",
  90. ]
  91. # Cache notebook outputs in _build/.jupyter_cache
  92. # To prevent notebook execution, set this to "off". To force re-execution, set this to "force".
  93. # To cache previous runs, set this to "cache".
  94. jupyter_execute_notebooks = os.getenv("RUN_NOTEBOOKS", "off")
  95. external_toc_exclude_missing = False
  96. external_toc_path = "_toc.yml"
  97. html_extra_path = ["robots.txt"]
  98. html_baseurl = "https://docs.ray.io/en/latest"
  99. # This pattern matches:
  100. # - Python Repl prompts (">>> ") and it's continuation ("... ")
  101. # - Bash prompts ("$ ")
  102. # - IPython prompts ("In []: ", "In [999]: ") and it's continuations
  103. # (" ...: ", " : ")
  104. copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
  105. copybutton_prompt_is_regexp = True
  106. # By default, tabs can be closed by selecting an open tab. We disable this
  107. # functionality with the `sphinx_tabs_disable_tab_closing` option.
  108. sphinx_tabs_disable_tab_closing = True
  109. # There's a flaky autodoc import for "TensorFlowVariables" that fails depending on the doc structure / order
  110. # of imports.
  111. # autodoc_mock_imports = ["ray.experimental.tf_utils"]
  112. # This is used to suppress warnings about explicit "toctree" directives.
  113. suppress_warnings = ["etoc.toctree"]
  114. versionwarning_admonition_type = "note"
  115. versionwarning_banner_title = "Join the Ray Discuss Forums!"
  116. FORUM_LINK = "https://discuss.ray.io"
  117. versionwarning_messages = {
  118. # Re-enable this after Ray Summit.
  119. # "latest": (
  120. # "This document is for the latest pip release. "
  121. # 'Visit the <a href="/en/master/">master branch documentation here</a>.'
  122. # ),
  123. # "master": (
  124. # "<b>Got questions?</b> Join "
  125. # f'<a href="{FORUM_LINK}">the Ray Community forum</a> '
  126. # "for Q&A on all things Ray, as well as to share and learn use cases "
  127. # "and best practices with the Ray community."
  128. # ),
  129. }
  130. versionwarning_body_selector = "#main-content"
  131. # Add any paths that contain templates here, relative to this directory.
  132. templates_path = ["_templates"]
  133. # The encoding of source files.
  134. # source_encoding = 'utf-8-sig'
  135. # The master toctree document.
  136. master_doc = "index"
  137. # General information about the project.
  138. project = "Ray"
  139. copyright = str(datetime.now().year) + ", The Ray Team"
  140. author = "The Ray Team"
  141. # The version info for the project you're documenting, acts as replacement for
  142. # |version| and |release|, also used in various other places throughout the
  143. # built documents.
  144. from ray import __version__ as version
  145. # The full version, including alpha/beta/rc tags.
  146. release = version
  147. language = None
  148. # List of patterns, relative to source directory, that match files and
  149. # directories to ignore when looking for source files.
  150. # Also helps resolve warnings about documents not included in any toctree.
  151. exclude_patterns = [
  152. "templates/*",
  153. "workflows/api/doc/ray.workflow.*",
  154. "serve/api/doc/ray.serve.*",
  155. "ray-references/api/ray-observability/state/doc/ray.*",
  156. "ray-observability/reference/doc/ray.*",
  157. "cluster/running-applications/doc/ray.*",
  158. ]
  159. # If "DOC_LIB" is found, only build that top-level navigation item.
  160. build_one_lib = os.getenv("DOC_LIB")
  161. all_toc_libs = [f.path for f in os.scandir(".") if f.is_dir() and "ray-" in f.path]
  162. all_toc_libs += [
  163. "cluster",
  164. "tune",
  165. "data",
  166. "train",
  167. "rllib",
  168. "serve",
  169. "workflows",
  170. ]
  171. if build_one_lib and build_one_lib in all_toc_libs:
  172. all_toc_libs.remove(build_one_lib)
  173. exclude_patterns += all_toc_libs
  174. # The name of the Pygments (syntax highlighting) style to use.
  175. pygments_style = "lovelace"
  176. # If true, `todo` and `todoList` produce output, else they produce nothing.
  177. todo_include_todos = False
  178. # Do not check anchors for links because it produces many false positives
  179. # and is slow (it needs to download the linked website).
  180. linkcheck_anchors = False
  181. # Only check external links, i.e. the ones starting with http:// or https://.
  182. linkcheck_ignore = [
  183. r"^((?!http).)*$", # exclude links not starting with http
  184. "http://ala2017.it.nuigalway.ie/papers/ALA2017_Gupta.pdf", # broken
  185. "https://mvnrepository.com/artifact/*", # working but somehow not with linkcheck
  186. # This should be fixed -- is temporal the successor of cadence? Do the examples need to be updated?
  187. "https://github.com/serverlessworkflow/specification/blob/main/comparisons/comparison-cadence.md",
  188. # TODO(richardliaw): The following probably needs to be fixed in the tune_sklearn package
  189. "https://scikit-optimize.github.io/stable/modules/",
  190. "https://www.oracle.com/java/technologies/javase-jdk15-downloads.html", # forbidden for client
  191. "https://speakerdeck.com/*", # forbidden for bots
  192. r"https://huggingface.co/*", # seems to be flaky
  193. r"https://www.meetup.com/*", # seems to be flaky
  194. r"https://www.pettingzoo.ml/*", # seems to be flaky
  195. r"http://localhost[:/].*", # Ignore localhost links
  196. r"^http:/$", # Ignore incomplete links
  197. # 403 Client Error: Forbidden for url.
  198. # They ratelimit bots.
  199. "https://www.datanami.com/2018/02/01/rays-new-library-targets-high-speed-reinforcement-learning/",
  200. # 403 Client Error: Forbidden for url.
  201. # They ratelimit bots.
  202. "https://www.researchgate.net/publication/222573328_Stochastic_Gradient_Boosting",
  203. "https://www.datanami.com/2019/11/05/why-every-python-developer-will-love-ray/",
  204. "https://dev.mysql.com/doc/connector-python/en/",
  205. # Returning 522s intermittently.
  206. "https://lczero.org/",
  207. ]
  208. # -- Options for HTML output ----------------------------------------------
  209. # The theme to use for HTML and HTML Help pages. See the documentation for
  210. # a list of builtin themes.
  211. html_theme = "sphinx_book_theme"
  212. # Theme options are theme-specific and customize the look and feel of a theme
  213. # further. For a list of options available for each theme, see the
  214. # documentation.
  215. html_theme_options = {
  216. "repository_url": "https://github.com/ray-project/ray",
  217. "use_repository_button": True,
  218. "use_issues_button": True,
  219. "use_edit_page_button": True,
  220. "path_to_docs": "doc/source",
  221. "home_page_in_toc": True,
  222. "show_navbar_depth": 1,
  223. "announcement": "<div class='topnav'></div>",
  224. }
  225. # Add any paths that contain custom themes here, relative to this directory.
  226. # html_theme_path = []
  227. # The name for this set of Sphinx documents. If None, it defaults to
  228. # "<project> v<release> documentation".
  229. html_title = f"Ray {release}"
  230. # A shorter title for the navigation bar. Default is the same as html_title.
  231. # html_short_title = None
  232. # The name of an image file (within the static path) to use as favicon of the
  233. # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
  234. # pixels large.
  235. html_favicon = "_static/favicon.ico"
  236. # Add any paths that contain custom static files (such as style sheets) here,
  237. # relative to this directory. They are copied after the builtin static files,
  238. # so a file named "default.css" will overwrite the builtin "default.css".
  239. html_static_path = ["_static"]
  240. # Output file base name for HTML help builder.
  241. htmlhelp_basename = "Raydoc"
  242. # -- Options for LaTeX output ---------------------------------------------
  243. latex_elements = {
  244. # The paper size ('letterpaper' or 'a4paper').
  245. # 'papersize': 'letterpaper',
  246. # The font size ('10pt', '11pt' or '12pt').
  247. # 'pointsize': '10pt',
  248. # Additional stuff for the LaTeX preamble.
  249. # 'preamble': '',
  250. # Latex figure (float) alignment
  251. # 'figure_align': 'htbp',
  252. }
  253. latex_documents = [
  254. (master_doc, "Ray.tex", "Ray Documentation", author, "manual"),
  255. ]
  256. # -- Options for manual page output ---------------------------------------
  257. man_pages = [(master_doc, "ray", "Ray Documentation", [author], 1)]
  258. # -- Options for Texinfo output -------------------------------------------
  259. texinfo_documents = [
  260. (
  261. master_doc,
  262. "Ray",
  263. "Ray Documentation",
  264. author,
  265. "Ray",
  266. "Ray provides a simple, universal API for building distributed applications.",
  267. "Miscellaneous",
  268. ),
  269. ]
  270. # Python methods should be presented in source code order
  271. autodoc_member_order = "bysource"
  272. # Better typehint formatting (see custom.css)
  273. autodoc_typehints = "signature"
  274. def filter_out_undoc_class_members(member_name, class_name, module_name):
  275. module = import_module(module_name)
  276. cls = getattr(module, class_name)
  277. if getattr(cls, member_name).__doc__:
  278. return f"~{class_name}.{member_name}"
  279. else:
  280. return ""
  281. FILTERS["filter_out_undoc_class_members"] = filter_out_undoc_class_members
  282. # Add a render priority for doctest
  283. nb_render_priority = {
  284. "doctest": (),
  285. "html": (
  286. "application/vnd.jupyter.widget-view+json",
  287. "application/javascript",
  288. "text/html",
  289. "image/svg+xml",
  290. "image/png",
  291. "image/jpeg",
  292. "text/markdown",
  293. "text/latex",
  294. "text/plain",
  295. ),
  296. }
  297. def setup(app):
  298. # NOTE: 'MOCK' is a custom option we introduced to illustrate mock outputs. Since
  299. # `doctest` doesn't support this flag by default, `sphinx.ext.doctest` raises
  300. # warnings when we build the documentation.
  301. import doctest
  302. doctest.register_optionflag("MOCK")
  303. app.connect("html-page-context", update_context)
  304. # Custom CSS
  305. app.add_css_file("css/custom.css", priority=800)
  306. app.add_css_file(
  307. "https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css"
  308. )
  309. # https://github.com/ines/termynal
  310. app.add_css_file("css/termynal.css")
  311. # Custom JS
  312. app.add_js_file(
  313. "https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js",
  314. defer="defer",
  315. )
  316. app.add_js_file("js/docsearch.js", defer="defer")
  317. # https://github.com/medmunds/rate-the-docs for allowing users
  318. # to give thumbs up / down and feedback on existing docs pages.
  319. app.add_js_file("js/rate-the-docs.es.min.js")
  320. # https://github.com/ines/termynal
  321. app.add_js_file("js/termynal.js", defer="defer")
  322. app.add_js_file("js/custom.js", defer="defer")
  323. app.add_js_file("js/top-navigation.js", defer="defer")
  324. base_path = Path(__file__).parent
  325. github_docs = DownloadAndPreprocessEcosystemDocs(base_path)
  326. # Download docs from ecosystem library repos
  327. app.connect("builder-inited", github_docs.write_new_docs)
  328. # Restore original file content after build
  329. app.connect("build-finished", github_docs.write_original_docs)
  330. # Hook into the logger used by linkcheck to display a summary at the end.
  331. linkcheck_summarizer = LinkcheckSummarizer()
  332. app.connect("builder-inited", linkcheck_summarizer.add_handler_to_linkcheck)
  333. app.connect("build-finished", linkcheck_summarizer.summarize)
  334. # Create galleries on the fly
  335. app.connect("builder-inited", build_gallery)
  336. # tag filtering system
  337. app.add_js_file("js/tags.js")
  338. redoc = [
  339. {
  340. "name": "Ray Jobs API",
  341. "page": "cluster/running-applications/job-submission/api",
  342. "spec": "cluster/running-applications/job-submission/openapi.yml",
  343. "embed": True,
  344. },
  345. ]
  346. redoc_uri = "https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"
  347. autosummary_filename_map = {
  348. "ray.serve.deployment": "ray.serve.deployment_decorator",
  349. "ray.serve.Deployment": "ray.serve.Deployment",
  350. }