2019-06-22 22:22:39 +00:00
|
|
|
# Configuration file for the Sphinx documentation builder.
|
|
|
|
|
|
|
|
# -- Path setup --------------------------------------------------------------
|
|
|
|
|
2022-01-27 08:03:50 +00:00
|
|
|
import atexit
|
2021-04-13 21:14:37 +00:00
|
|
|
import os
|
2022-01-27 08:03:50 +00:00
|
|
|
import shutil
|
2021-04-13 21:14:37 +00:00
|
|
|
import subprocess
|
2022-02-21 22:27:03 +00:00
|
|
|
import sys
|
2022-01-27 08:03:50 +00:00
|
|
|
from pathlib import Path
|
2022-02-20 22:13:37 +00:00
|
|
|
from typing import Any
|
2022-04-09 20:41:10 +00:00
|
|
|
from unittest import mock
|
2019-06-22 22:22:39 +00:00
|
|
|
|
2022-12-14 08:11:19 +00:00
|
|
|
import micropip
|
|
|
|
|
2022-09-21 04:03:18 +00:00
|
|
|
panels_add_bootstrap_css = False
|
|
|
|
|
2019-06-22 22:22:39 +00:00
|
|
|
# -- Project information -----------------------------------------------------
|
|
|
|
|
|
|
|
project = "Pyodide"
|
2022-05-30 01:26:40 +00:00
|
|
|
copyright = "2019-2022, Pyodide contributors and Mozilla"
|
2019-06-22 22:22:39 +00:00
|
|
|
|
|
|
|
# -- General configuration ---------------------------------------------------
|
|
|
|
|
|
|
|
# If your documentation needs a minimal Sphinx version, state it here.
|
|
|
|
#
|
|
|
|
# needs_sphinx = '1.0'
|
|
|
|
|
2020-10-31 20:00:58 +00:00
|
|
|
extensions = [
|
|
|
|
"sphinx.ext.autodoc",
|
|
|
|
"sphinx.ext.autosummary",
|
2022-12-14 08:11:19 +00:00
|
|
|
"sphinx.ext.intersphinx",
|
2023-01-14 14:01:20 +00:00
|
|
|
"sphinx.ext.napoleon",
|
2020-10-31 20:00:58 +00:00
|
|
|
"myst_parser",
|
2021-02-06 20:17:57 +00:00
|
|
|
"sphinx_js",
|
2022-12-22 10:24:28 +00:00
|
|
|
"sphinx_click",
|
2021-03-22 08:39:09 +00:00
|
|
|
"autodocsumm",
|
|
|
|
"sphinx_pyodide",
|
2021-04-15 16:54:26 +00:00
|
|
|
"sphinx_argparse_cli",
|
2022-01-17 04:00:22 +00:00
|
|
|
"versionwarning.extension",
|
2021-04-19 00:59:19 +00:00
|
|
|
"sphinx_issues",
|
2023-01-04 09:51:09 +00:00
|
|
|
"sphinx_autodoc_typehints",
|
2023-01-18 06:35:30 +00:00
|
|
|
"sphinx_design", # Used for tabs in building-from-sources.md
|
2020-10-31 20:00:58 +00:00
|
|
|
]
|
|
|
|
|
2022-12-14 08:11:19 +00:00
|
|
|
|
2021-02-15 07:59:38 +00:00
|
|
|
myst_enable_extensions = ["substitution"]
|
2022-05-30 01:26:40 +00:00
|
|
|
|
2022-01-27 08:03:50 +00:00
|
|
|
js_language = "typescript"
|
|
|
|
jsdoc_config_path = "../src/js/tsconfig.json"
|
2021-03-25 16:26:07 +00:00
|
|
|
root_for_relative_js_paths = "../src/"
|
2021-04-19 00:59:19 +00:00
|
|
|
issues_github_path = "pyodide/pyodide"
|
2021-02-06 20:17:57 +00:00
|
|
|
|
2021-04-17 17:18:52 +00:00
|
|
|
versionwarning_messages = {
|
|
|
|
"latest": (
|
2022-01-17 04:00:22 +00:00
|
|
|
"This is the development version of the documentation. "
|
2021-04-17 17:18:52 +00:00
|
|
|
'See <a href="https://pyodide.org/">here</a> for latest stable '
|
|
|
|
"documentation. Please do not use Pyodide with non "
|
2022-01-17 04:00:22 +00:00
|
|
|
"versioned (`dev`) URLs from the CDN for deployed applications!"
|
2021-04-17 17:18:52 +00:00
|
|
|
)
|
|
|
|
}
|
2022-01-17 04:00:22 +00:00
|
|
|
versionwarning_body_selector = "#main-content > div"
|
2021-04-17 17:18:52 +00:00
|
|
|
|
2020-10-31 20:00:58 +00:00
|
|
|
autosummary_generate = True
|
|
|
|
autodoc_default_flags = ["members", "inherited-members"]
|
2019-06-22 22:22:39 +00:00
|
|
|
|
2022-12-14 08:11:19 +00:00
|
|
|
intersphinx_mapping = {
|
2023-01-04 09:51:09 +00:00
|
|
|
"python": ("https://docs.python.org/3.10", None),
|
|
|
|
"micropip": (f"https://micropip.pyodide.org/en/v{micropip.__version__}/", None),
|
2023-01-20 02:21:44 +00:00
|
|
|
"numpy": ("https://numpy.org/doc/stable/", None),
|
2022-12-14 08:11:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:41:10 +00:00
|
|
|
# Add modules to be mocked.
|
2023-01-17 03:59:07 +00:00
|
|
|
mock_modules = ["tomli"]
|
2022-04-09 20:41:10 +00:00
|
|
|
|
2019-06-22 22:22:39 +00:00
|
|
|
# Add any paths that contain templates here, relative to this directory.
|
|
|
|
templates_path = ["_templates"]
|
|
|
|
|
|
|
|
# The suffix(es) of source filenames.
|
|
|
|
source_suffix = [".rst", ".md"]
|
|
|
|
|
|
|
|
# The master toctree document.
|
|
|
|
master_doc = "index"
|
|
|
|
|
|
|
|
# List of patterns, relative to source directory, that match files and
|
|
|
|
# directories to ignore when looking for source files.
|
2023-01-01 15:44:35 +00:00
|
|
|
exclude_patterns = [
|
|
|
|
"_build",
|
|
|
|
"Thumbs.db",
|
|
|
|
".DS_Store",
|
|
|
|
"README.md",
|
|
|
|
"sphinx_pyodide",
|
2023-01-14 14:01:20 +00:00
|
|
|
".*",
|
2023-01-01 15:44:35 +00:00
|
|
|
]
|
2019-06-22 22:22:39 +00:00
|
|
|
|
|
|
|
# The name of the Pygments (syntax highlighting) style to use.
|
|
|
|
pygments_style = None
|
|
|
|
|
|
|
|
# -- Options for HTML output -------------------------------------------------
|
|
|
|
|
|
|
|
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
|
|
# a list of builtin themes.
|
|
|
|
#
|
2021-02-15 07:59:38 +00:00
|
|
|
html_theme = "sphinx_book_theme"
|
|
|
|
html_logo = "_static/img/pyodide-logo.png"
|
2019-06-22 22:22:39 +00:00
|
|
|
|
2021-03-22 08:39:09 +00:00
|
|
|
# theme-specific options
|
2022-02-20 22:13:37 +00:00
|
|
|
html_theme_options: dict[str, Any] = {}
|
2019-06-22 22:22:39 +00:00
|
|
|
|
2021-03-22 08:39:09 +00:00
|
|
|
# paths that contain custom static files (such as style sheets)
|
2019-06-22 22:22:39 +00:00
|
|
|
html_static_path = ["_static"]
|
|
|
|
|
2021-02-17 07:58:56 +00:00
|
|
|
|
|
|
|
html_css_files = [
|
|
|
|
"css/pyodide.css",
|
|
|
|
]
|
|
|
|
|
2019-06-22 22:22:39 +00:00
|
|
|
# Custom sidebar templates, must be a dictionary that maps document names
|
|
|
|
# to template names.
|
|
|
|
# html_sidebars = {}
|
|
|
|
|
|
|
|
# -- Options for HTMLHelp output ---------------------------------------------
|
|
|
|
|
|
|
|
# Output file base name for HTML help builder.
|
|
|
|
htmlhelp_basename = "Pyodidedoc"
|
|
|
|
|
|
|
|
# A list of files that should not be packed into the epub file.
|
|
|
|
epub_exclude_files = ["search.html"]
|
2021-04-13 21:14:37 +00:00
|
|
|
|
2023-01-24 21:11:31 +00:00
|
|
|
base_dir = Path(__file__).resolve().parent.parent
|
|
|
|
extra_sys_path_dirs = [
|
|
|
|
str(base_dir),
|
|
|
|
str(base_dir / "pyodide-build"),
|
|
|
|
str(base_dir / "docs/sphinx_pyodide"),
|
|
|
|
str(base_dir / "src/py"),
|
|
|
|
str(base_dir / "packages/micropip/src"),
|
|
|
|
]
|
2021-04-20 21:28:33 +00:00
|
|
|
|
2022-01-27 08:03:50 +00:00
|
|
|
# Try not to cause side effects if we are imported incidentally.
|
|
|
|
|
|
|
|
try:
|
|
|
|
import sphinx
|
|
|
|
|
|
|
|
IN_SPHINX = hasattr(sphinx, "application")
|
|
|
|
except ImportError:
|
|
|
|
IN_SPHINX = False
|
|
|
|
|
|
|
|
IN_READTHEDOCS = "READTHEDOCS" in os.environ
|
|
|
|
|
2023-01-24 21:11:31 +00:00
|
|
|
if IN_SPHINX:
|
|
|
|
sys.path = extra_sys_path_dirs + sys.path
|
|
|
|
import builtins
|
|
|
|
|
|
|
|
from sphinx_pyodide.util import docs_argspec
|
|
|
|
|
|
|
|
# override docs_argspec, _pyodide.docs_argspec will read this value back.
|
|
|
|
# Must do this before importing pyodide!
|
|
|
|
setattr(builtins, "--docs_argspec--", docs_argspec)
|
|
|
|
|
|
|
|
# Monkey patch for python3.11 incompatible code
|
|
|
|
import inspect
|
|
|
|
|
|
|
|
if not hasattr(inspect, "getargspec"):
|
|
|
|
inspect.getargspec = inspect.getfullargspec # type: ignore[assignment]
|
|
|
|
|
|
|
|
import pyodide
|
|
|
|
|
|
|
|
# The full version, including alpha/beta/rc tags.
|
|
|
|
release = version = pyodide.__version__
|
|
|
|
|
|
|
|
if ".dev" in version or os.environ.get("READTHEDOCS_VERSION") == "latest":
|
|
|
|
CDN_URL = "https://cdn.jsdelivr.net/pyodide/dev/full/"
|
|
|
|
else:
|
|
|
|
CDN_URL = f"https://cdn.jsdelivr.net/pyodide/v{version}/full/"
|
|
|
|
|
|
|
|
html_title = f"Version {version}"
|
|
|
|
|
|
|
|
global_replacements = {"{{PYODIDE_CDN_URL}}": CDN_URL, "{{VERSION}}": version}
|
|
|
|
|
|
|
|
|
2022-01-27 08:03:50 +00:00
|
|
|
if IN_READTHEDOCS:
|
2023-01-24 21:11:31 +00:00
|
|
|
# Make console.html file
|
2022-05-30 01:26:40 +00:00
|
|
|
env = {"PYODIDE_BASE_URL": CDN_URL}
|
2022-01-27 08:03:50 +00:00
|
|
|
os.makedirs("_build/html", exist_ok=True)
|
|
|
|
res = subprocess.check_output(
|
|
|
|
["make", "-C", "..", "docs/_build/html/console.html"],
|
|
|
|
env=env,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
encoding="utf-8",
|
|
|
|
)
|
|
|
|
print(res)
|
2022-08-23 07:15:11 +00:00
|
|
|
# insert the Plausible analytics script to console.html
|
|
|
|
console_path = Path("_build/html/console.html")
|
|
|
|
console_html = console_path.read_text().splitlines(keepends=True)
|
|
|
|
for idx, line in enumerate(list(console_html)):
|
|
|
|
if 'pyodide.js">' in line:
|
|
|
|
# insert the analytics script after the `pyodide.js` script
|
|
|
|
console_html.insert(
|
|
|
|
idx,
|
|
|
|
'<script defer data-domain="pyodide.org" src="https://plausible.io/js/plausible.js"></script>\n',
|
|
|
|
)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ValueError("Could not find pyodide.js in the <head> section")
|
|
|
|
console_path.write_text("".join(console_html))
|
|
|
|
|
2022-01-27 08:03:50 +00:00
|
|
|
|
|
|
|
if IN_SPHINX:
|
2022-11-21 02:52:19 +00:00
|
|
|
from sphinx.domains.javascript import JavaScriptDomain, JSXRefRole
|
|
|
|
|
2023-01-22 08:26:42 +00:00
|
|
|
JavaScriptDomain.roles["class"] = JSXRefRole()
|
2022-11-21 02:52:19 +00:00
|
|
|
|
2022-12-28 03:16:23 +00:00
|
|
|
from pyodide.ffi import JsProxy
|
|
|
|
|
|
|
|
del JsProxy.__new__
|
2022-01-27 08:03:50 +00:00
|
|
|
|
|
|
|
shutil.copy("../src/core/pyproxy.ts", "../src/js/pyproxy.gen.ts")
|
|
|
|
shutil.copy("../src/core/error_handling.ts", "../src/js/error_handling.gen.ts")
|
|
|
|
js_source_path = [str(x) for x in Path("../src/js").glob("*.ts")]
|
|
|
|
|
|
|
|
def remove_pyproxy_gen_ts():
|
|
|
|
Path("../src/js/pyproxy.gen.ts").unlink(missing_ok=True)
|
|
|
|
|
|
|
|
atexit.register(remove_pyproxy_gen_ts)
|
|
|
|
|
|
|
|
os.environ["PATH"] += f':{str(Path("../src/js/node_modules/.bin").resolve())}'
|
|
|
|
print(os.environ["PATH"])
|
|
|
|
if IN_READTHEDOCS:
|
|
|
|
subprocess.run(["npm", "ci"], cwd="../src/js")
|
|
|
|
elif not shutil.which("typedoc"):
|
|
|
|
raise Exception(
|
|
|
|
"Before building the Pyodide docs you must run 'npm install' in 'src/js'."
|
|
|
|
)
|
|
|
|
|
|
|
|
# Prevent API docs for webloop methods: they are the same as for base event loop
|
|
|
|
# and it clutters api docs too much
|
2023-01-24 21:11:31 +00:00
|
|
|
from sphinx_pyodide.util import delete_attrs
|
|
|
|
|
2023-01-14 14:01:20 +00:00
|
|
|
import pyodide.console
|
|
|
|
import pyodide.webloop
|
|
|
|
|
2022-01-27 08:03:50 +00:00
|
|
|
delete_attrs(pyodide.webloop.WebLoop)
|
|
|
|
delete_attrs(pyodide.webloop.WebLoopPolicy)
|
|
|
|
delete_attrs(pyodide.console.PyodideConsole)
|
2022-04-09 20:41:10 +00:00
|
|
|
|
|
|
|
for module in mock_modules:
|
|
|
|
sys.modules[module] = mock.Mock()
|
2022-05-30 01:26:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
# https://github.com/sphinx-doc/sphinx/issues/4054
|
|
|
|
def globalReplace(app, docname, source):
|
|
|
|
result = source[0]
|
|
|
|
for key in app.config.global_replacements:
|
|
|
|
result = result.replace(key, app.config.global_replacements[key])
|
|
|
|
source[0] = result
|
|
|
|
|
|
|
|
|
2023-01-18 22:13:17 +00:00
|
|
|
always_document_param_types = True
|
|
|
|
|
2023-01-04 09:51:09 +00:00
|
|
|
|
2023-01-17 03:59:07 +00:00
|
|
|
def typehints_formatter(annotation, config):
|
|
|
|
"""Adjust the rendering of various types that sphinx_autodoc_typehints mishandles"""
|
2023-01-04 09:51:09 +00:00
|
|
|
from sphinx_autodoc_typehints import (
|
|
|
|
get_annotation_class_name,
|
|
|
|
get_annotation_module,
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
module = get_annotation_module(annotation)
|
|
|
|
class_name = get_annotation_class_name(annotation, module)
|
|
|
|
except ValueError:
|
|
|
|
return None
|
|
|
|
full_name = f"{module}.{class_name}"
|
2023-01-18 22:13:37 +00:00
|
|
|
if full_name == "typing.TypeVar":
|
|
|
|
# The way sphinx-autodoc-typehints renders TypeVar is too noisy for my
|
|
|
|
# taste
|
|
|
|
return f"``{annotation.__name__}``"
|
2023-01-18 05:00:39 +00:00
|
|
|
if full_name == "ast.Module":
|
|
|
|
return "`Module <https://docs.python.org/3/library/ast.html#module-ast>`_"
|
2023-01-04 09:51:09 +00:00
|
|
|
return None
|
|
|
|
|
2022-05-30 01:26:40 +00:00
|
|
|
|
|
|
|
def setup(app):
|
|
|
|
app.add_config_value("global_replacements", {}, True)
|
|
|
|
app.connect("source-read", globalReplace)
|