-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
conf.py
585 lines (492 loc) · 19 KB
/
conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
from typing import Dict, Any
from datetime import datetime
from importlib import import_module
import os
import sys
from jinja2.filters import FILTERS
import sphinx
from sphinx.ext import autodoc
from docutils import nodes
import pathlib
import logging
logger = logging.getLogger(__name__)
sys.path.insert(0, os.path.abspath("."))
from custom_directives import ( # noqa
DownloadAndPreprocessEcosystemDocs,
update_context,
LinkcheckSummarizer,
parse_navbar_config,
setup_context,
pregenerate_example_rsts,
)
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath("../../python/"))
# -- General configuration ------------------------------------------------
# The name of a reST role (builtin or Sphinx extension) to use as the default role, that
# is, for text marked up `like this`. This can be set to 'py:obj' to make `filter` a
# cross-reference to the Python function “filter”. The default is None, which doesn’t
# reassign the default role.
default_role = "py:obj"
sys.path.append(os.path.abspath("./_ext"))
extensions = [
"callouts", # custom extension from _ext folder
"queryparamrefs",
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx_click.ext",
"sphinx-jsonschema",
"sphinxemoji.sphinxemoji",
"sphinx_copybutton",
"sphinx_sitemap",
"myst_nb",
"sphinx.ext.doctest",
"sphinx.ext.coverage",
"sphinx.ext.autosummary",
"sphinxcontrib.autodoc_pydantic",
"sphinxcontrib.redoc",
"sphinx_remove_toctrees",
"sphinx_design",
"sphinx.ext.intersphinx",
]
remove_from_toctrees = [
"cluster/running-applications/job-submission/doc/*",
"ray-observability/reference/doc/*",
"ray-core/api/doc/*",
"data/api/doc/*",
"train/api/doc/*",
"tune/api/doc/*",
"serve/api/doc/*",
"rllib/package_ref/algorithm/*",
"rllib/package_ref/policy/*",
"rllib/package_ref/models/*",
"rllib/package_ref/catalogs/*",
"rllib/package_ref/rl_modules/*",
"rllib/package_ref/learner/*",
"rllib/package_ref/evaluation/*",
"rllib/package_ref/replay-buffers/*",
"rllib/package_ref/utils/*",
]
myst_enable_extensions = [
"dollarmath",
"amsmath",
"deflist",
"html_admonition",
"html_image",
"colon_fence",
"smartquotes",
"replacements",
]
myst_heading_anchors = 3
# Cache notebook outputs in _build/.jupyter_cache
# To prevent notebook execution, set this to "off". To force re-execution, set this to
# "force". To cache previous runs, set this to "cache".
nb_execution_mode = os.getenv("RUN_NOTEBOOKS", "off")
# Add a render priority for doctest
nb_mime_priority_overrides = [
("html", "application/vnd.jupyter.widget-view+json", 10),
("html", "application/javascript", 20),
("html", "text/html", 30),
("html", "image/svg+xml", 40),
("html", "image/png", 50),
("html", "image/jpeg", 60),
("html", "text/markdown", 70),
("html", "text/latex", 80),
("html", "text/plain", 90),
]
html_extra_path = ["robots.txt"]
html_baseurl = "https://docs.ray.io/en/latest"
# This pattern matches:
# - Python Repl prompts (">>> ") and it's continuation ("... ")
# - Bash prompts ("$ ")
# - IPython prompts ("In []: ", "In [999]: ") and it's continuations
# (" ...: ", " : ")
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_is_regexp = True
# Ignore divs with class="no-copybutton"
copybutton_selector = "div:not(.no-copybutton) > div.highlight > pre"
# By default, tabs can be closed by selecting an open tab. We disable this
# functionality with the `sphinx_tabs_disable_tab_closing` option.
sphinx_tabs_disable_tab_closing = True
# Special mocking of packaging.version.Version is required when using sphinx;
# we can't just add this to autodoc_mock_imports, as packaging is imported by
# sphinx even before it can be mocked. Instead, we patch it here.
import packaging.version as packaging_version # noqa
Version = packaging_version.Version
class MockVersion(Version):
def __init__(self, version: str):
if isinstance(version, (str, bytes)):
super().__init__(version)
else:
super().__init__("0")
packaging_version.Version = MockVersion
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# The master toctree document.
master_doc = "index"
# General information about the project.
project = "Ray"
copyright = str(datetime.now().year) + ", The Ray Team"
author = "The Ray Team"
# The version info for the project you're documenting acts as replacement for
# |version| and |release|, and is also used in various other places throughout the
# built documents. Retrieve the version using `find_version` rather than importing
# directly (from ray import __version__) because initializing ray will prevent
# mocking of certain external dependencies.
from setup import find_version # noqa
release = find_version("ray", "_version.py")
language = "en"
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# Also helps resolve warnings about documents not included in any toctree.
exclude_patterns = [
"templates/*",
"cluster/running-applications/doc/ray.*",
]
# If "DOC_LIB" is found, only build that top-level navigation item.
build_one_lib = os.getenv("DOC_LIB")
all_toc_libs = [
f.path.strip("./") for f in os.scandir(".") if f.is_dir() and "ray-" in f.path
]
all_toc_libs += [
"cluster",
"tune",
"data",
"train",
"rllib",
"serve",
"workflows",
]
if build_one_lib and build_one_lib in all_toc_libs:
all_toc_libs.remove(build_one_lib)
exclude_patterns += all_toc_libs
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# Do not check anchors for links because it produces many false positives
# and is slow (it needs to download the linked website).
linkcheck_anchors = False
if os.environ.get("LINKCHECK_ALL"):
# Only check external links, i.e. the ones starting with http:// or https://.
linkcheck_ignore = [
r"^((?!http).)*$", # exclude links not starting with http
"http://ala2017.it.nuigalway.ie/papers/ALA2017_Gupta.pdf", # broken
"https://mvnrepository.com/artifact/*", # working but somehow not with linkcheck
# This should be fixed -- is temporal the successor of cadence? Do the examples need to be updated?
"https://github.com/serverlessworkflow/specification/blob/main/comparisons/comparison-cadence.md",
# TODO(richardliaw): The following probably needs to be fixed in the tune_sklearn package
"https://www.oracle.com/java/technologies/javase-jdk15-downloads.html", # forbidden for client
"https://speakerdeck.com/*", # forbidden for bots
r"https://huggingface.co/*", # seems to be flaky
r"https://www.meetup.com/*", # seems to be flaky
r"https://www.pettingzoo.ml/*", # seems to be flaky
r"http://localhost[:/].*", # Ignore localhost links
r"^http:/$", # Ignore incomplete links
# 403 Client Error: Forbidden for url.
# They ratelimit bots.
"https://www.datanami.com/2018/02/01/rays-new-library-targets-high-speed-reinforcement-learning/",
# 403 Client Error: Forbidden for url.
# They ratelimit bots.
"https://www.researchgate.net/publication/222573328_Stochastic_Gradient_Boosting",
"https://www.datanami.com/2019/11/05/why-every-python-developer-will-love-ray/",
"https://dev.mysql.com/doc/connector-python/en/",
# Returning 522s intermittently.
"https://lczero.org/",
# Returns 406 but remains accessible
"https://www.uber.com/blog/elastic-xgboost-ray/",
# Aggressive anti-bot checks
"https://archive.vn/*",
"https://archive.is/*",
# 429: Rate limited
"https://medium.com/*",
"https://towardsdatascience.com/*",
]
else:
# Only check links that point to the ray-project org on github, since those
# links are under our control and therefore much more likely to be real
# issues that we need to fix if they are broken.
linkcheck_ignore = [
r"^(?!https://(raw\.githubusercontent|github)\.com/ray-project/).*$"
]
# -- Options for HTML output ----------------------------------------------
def render_svg_logo(path):
with open(pathlib.Path(__file__).parent / path, "r") as f:
content = f.read()
return content
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "pydata_sphinx_theme"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"use_edit_page_button": True,
"announcement": None,
"logo": {
"svg": render_svg_logo("_static/img/ray_logo.svg"),
},
"navbar_start": ["navbar-ray-logo"],
"navbar_end": [
"navbar-icon-links",
"navbar-anyscale",
],
"navbar_center": ["navbar-links"],
"navbar_align": "left",
"navbar_persistent": [
"search-button-field",
"theme-switcher",
],
"secondary_sidebar_items": [
"page-toc",
"edit-this-page",
],
"content_footer_items": [
"csat",
],
"navigation_depth": 4,
"analytics": {"google_analytics_id": "UA-110413294-1"},
"pygment_light_style": "stata-dark",
"pygment_dark_style": "stata-dark",
}
html_context = {
"github_user": "ray-project",
"github_repo": "ray",
"github_version": "master",
"doc_path": "doc/source/",
}
html_sidebars = {
"**": ["main-sidebar"],
"ray-overview/examples": [],
}
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
html_title = f"Ray {release}"
autodoc_typehints_format = "short"
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = "_static/favicon.ico"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
# Output file base name for HTML help builder.
htmlhelp_basename = "Raydoc"
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
# Latex figure (float) alignment
# 'figure_align': 'htbp',
}
latex_documents = [
(master_doc, "Ray.tex", "Ray Documentation", author, "manual"),
]
# -- Options for manual page output ---------------------------------------
man_pages = [(master_doc, "ray", "Ray Documentation", [author], 1)]
# -- Options for Texinfo output -------------------------------------------
texinfo_documents = [
(
master_doc,
"Ray",
"Ray Documentation",
author,
"Ray",
"Ray provides a simple, universal API for building distributed applications.",
"Miscellaneous",
),
]
# Python methods should be presented in source code order
autodoc_member_order = "bysource"
# Better typehint formatting (see custom.css)
autodoc_typehints = "signature"
def filter_out_undoc_class_members(member_name, class_name, module_name):
module = import_module(module_name)
cls = getattr(module, class_name)
if getattr(cls, member_name).__doc__:
return f"~{class_name}.{member_name}"
else:
return ""
FILTERS["filter_out_undoc_class_members"] = filter_out_undoc_class_members
def add_custom_assets(
app: sphinx.application.Sphinx,
pagename: str,
templatename: str,
context: Dict[str, Any],
doctree: nodes.Node,
):
"""Add custom per-page assets.
See documentation on Sphinx Core Events for more information:
https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx-core-events
"""
if pagename == "index":
app.add_css_file("css/index.css")
app.add_js_file("js/index.js")
return "index.html" # Use the special index.html template for this page
if pagename == "ray-overview/examples":
app.add_css_file("css/examples.css")
app.add_js_file("js/examples.js")
return "ray-overview/examples.html"
if pagename in [
"data/examples",
"train/examples",
"serve/examples",
]:
return "examples.html"
if pagename == "train/train":
app.add_css_file("css/ray-train.css")
elif pagename == "ray-overview/ray-libraries":
app.add_css_file("css/ray-libraries.css")
elif pagename == "ray-overview/use-cases":
app.add_css_file("css/use_cases.css")
def setup(app):
pregenerate_example_rsts(app)
# NOTE: 'MOCK' is a custom option we introduced to illustrate mock outputs. Since
# `doctest` doesn't support this flag by default, `sphinx.ext.doctest` raises
# warnings when we build the documentation.
import doctest
doctest.register_optionflag("MOCK")
app.connect("html-page-context", update_context)
app.add_config_value("navbar_content_path", "navbar.yml", "env")
app.connect("config-inited", parse_navbar_config)
app.connect("html-page-context", setup_context)
app.connect("html-page-context", add_custom_assets)
# https://github.com/ines/termynal
app.add_js_file("js/termynal.js", defer="defer")
app.add_css_file("css/termynal.css")
app.add_js_file("js/custom.js", defer="defer")
app.add_css_file("css/custom.css", priority=800)
app.add_js_file("js/csat.js")
app.add_css_file("css/csat.css")
app.add_js_file("js/assistant.js", defer="defer")
app.add_css_file("css/assistant.css")
base_path = pathlib.Path(__file__).parent
github_docs = DownloadAndPreprocessEcosystemDocs(base_path)
# Download docs from ecosystem library repos
app.connect("builder-inited", github_docs.write_new_docs)
# Restore original file content after build
app.connect("build-finished", github_docs.write_original_docs)
# Hook into the logger used by linkcheck to display a summary at the end.
linkcheck_summarizer = LinkcheckSummarizer()
app.connect("builder-inited", linkcheck_summarizer.add_handler_to_linkcheck)
app.connect("build-finished", linkcheck_summarizer.summarize)
redoc = [
{
"name": "Ray Jobs API",
"page": "cluster/running-applications/job-submission/api",
"spec": "cluster/running-applications/job-submission/openapi.yml",
"embed": True,
},
]
redoc_uri = "https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"
autosummary_filename_map = {
"ray.serve.deployment": "ray.serve.deployment_decorator",
"ray.serve.Deployment": "ray.serve.Deployment",
}
# Mock out external dependencies here.
autodoc_mock_imports = [
"aiohttp",
"aiosignal",
"composer",
"dask",
"datasets",
"fastapi",
"filelock",
"frozenlist",
"fsspec",
"google",
"grpc",
"gymnasium",
"horovod",
"huggingface",
"joblib",
"lightgbm",
"lightgbm_ray",
"nevergrad",
"numpy",
"pandas",
"pyarrow",
"pytorch_lightning",
"scipy",
"setproctitle",
"skimage",
"sklearn",
"starlette",
"tensorflow",
"torch",
"torchvision",
"transformers",
"tree",
"typer",
"uvicorn",
"wandb",
"watchfiles",
"xgboost",
"xgboost_ray",
"psutil",
"colorama",
"grpc",
# Internal compiled modules
"ray._raylet",
"ray.core.generated",
"ray.serve.generated",
]
for mock_target in autodoc_mock_imports:
if mock_target in sys.modules:
logger.info(
f"Potentially problematic mock target ({mock_target}) found; "
"autodoc_mock_imports cannot mock modules that have already "
"been loaded into sys.modules when the sphinx build starts."
)
class MockedClassDocumenter(autodoc.ClassDocumenter):
"""Remove note about base class when a class is derived from object."""
def add_line(self, line: str, source: str, *lineno: int) -> None:
if line == " Bases: :py:class:`object`":
return
super().add_line(line, source, *lineno)
autodoc.ClassDocumenter = MockedClassDocumenter
# Other sphinx docs can be linked to if the appropriate URL to the docs
# is specified in the `intersphinx_mapping` - for example, types annotations
# that are defined in dependencies can link to their respective documentation.
intersphinx_mapping = {
"aiohttp": ("https://docs.aiohttp.org/en/stable/", None),
"composer": ("https://docs.mosaicml.com/en/latest/", None),
"dask": ("https://docs.dask.org/en/stable/", None),
"datasets": ("https://huggingface.co/docs/datasets/main/en/", None),
"distributed": ("https://distributed.dask.org/en/stable/", None),
"grpc": ("https://grpc.github.io/grpc/python/", None),
"gymnasium": ("https://gymnasium.farama.org/", None),
"horovod": ("https://horovod.readthedocs.io/en/stable/", None),
"lightgbm": ("https://lightgbm.readthedocs.io/en/latest/", None),
"mars": ("https://mars-project.readthedocs.io/en/latest/", None),
"modin": ("https://modin.readthedocs.io/en/stable/", None),
"nevergrad": ("https://facebookresearch.github.io/nevergrad/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"pyarrow": ("https://arrow.apache.org/docs", None),
"pydantic": ("https://docs.pydantic.dev/latest/", None),
"pymongoarrow": ("https://mongo-arrow.readthedocs.io/en/latest/", None),
"pyspark": ("https://spark.apache.org/docs/latest/api/python/", None),
"python": ("https://docs.python.org/3", None),
"pytorch_lightning": ("https://lightning.ai/docs/pytorch/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"sklearn": ("https://scikit-learn.org/stable/", None),
"tensorflow": (
"https://www.tensorflow.org/api_docs/python",
"https://raw.githubusercontent.com/GPflow/tensorflow-intersphinx/master/tf2_py_objects.inv",
),
"torch": ("https://pytorch.org/docs/stable/", None),
"torchvision": ("https://pytorch.org/vision/stable/", None),
"transformers": ("https://huggingface.co/docs/transformers/main/en/", None),
}
# Ray must not be imported in conf.py because third party modules initialized by
# `import ray` will no be mocked out correctly. Perform a check here to ensure
# ray is not imported by future maintainers.
assert (
"ray" not in sys.modules
), "If ray is already imported, we will not render documentation correctly!"