| 1 |
# Configuration file for the Sphinx documentation builder. |
| 2 |
# |
| 3 |
# This file only contains a selection of the most common options. For a full |
| 4 |
# list see the documentation: |
| 5 |
# https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 6 |
|
| 7 |
import datetime |
| 8 |
import importlib |
| 9 |
import inspect |
| 10 |
import os |
| 11 |
import sys |
| 12 |
|
| 13 |
from websockets.version import commit |
| 14 |
|
| 15 |
|
| 16 |
# -- Path setup -------------------------------------------------------------- |
| 17 |
|
| 18 |
# If extensions (or modules to document with autodoc) are in another directory, |
| 19 |
# add these directories to sys.path here. If the directory is relative to the |
| 20 |
# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 21 |
sys.path.insert(0, os.path.join(os.path.abspath(".."), "src")) |
| 22 |
|
| 23 |
|
| 24 |
# -- Project information ----------------------------------------------------- |
| 25 |
|
| 26 |
project = "websockets" |
| 27 |
copyright = f"2013-{datetime.date.today().year}, Aymeric Augustin and contributors" |
| 28 |
author = "Aymeric Augustin" |
| 29 |
|
| 30 |
from websockets.version import tag as version, version as release # noqa: E402, F401 |
| 31 |
|
| 32 |
|
| 33 |
# -- General configuration --------------------------------------------------- |
| 34 |
|
| 35 |
nitpicky = True |
| 36 |
|
| 37 |
nitpick_ignore = [ |
| 38 |
# Workaround for https://github.com/sphinx-doc/sphinx/issues/13838 |
| 39 |
# This prevents a warning from being displayed when building docs, |
| 40 |
# but doesn't result in creating a correct link to ssl.SSLContext. |
| 41 |
("py:class", "ssl_module.SSLContext"), |
| 42 |
# topics/design.rst discusses undocumented APIs |
| 43 |
("py:meth", "client.WebSocketClientProtocol.handshake"), |
| 44 |
("py:meth", "server.WebSocketServerProtocol.handshake"), |
| 45 |
("py:attr", "protocol.WebSocketCommonProtocol.is_client"), |
| 46 |
("py:attr", "protocol.WebSocketCommonProtocol.messages"), |
| 47 |
("py:meth", "protocol.WebSocketCommonProtocol.close_connection"), |
| 48 |
("py:attr", "protocol.WebSocketCommonProtocol.close_connection_task"), |
| 49 |
("py:meth", "protocol.WebSocketCommonProtocol.keepalive_ping"), |
| 50 |
("py:attr", "protocol.WebSocketCommonProtocol.keepalive_ping_task"), |
| 51 |
("py:meth", "protocol.WebSocketCommonProtocol.transfer_data"), |
| 52 |
("py:attr", "protocol.WebSocketCommonProtocol.transfer_data_task"), |
| 53 |
("py:meth", "protocol.WebSocketCommonProtocol.connection_open"), |
| 54 |
("py:meth", "protocol.WebSocketCommonProtocol.ensure_open"), |
| 55 |
("py:meth", "protocol.WebSocketCommonProtocol.fail_connection"), |
| 56 |
("py:meth", "protocol.WebSocketCommonProtocol.connection_lost"), |
| 57 |
("py:meth", "protocol.WebSocketCommonProtocol.read_message"), |
| 58 |
("py:meth", "protocol.WebSocketCommonProtocol.write_frame"), |
| 59 |
] |
| 60 |
|
| 61 |
# Add any Sphinx extension module names here, as strings. They can be |
| 62 |
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 63 |
# ones. |
| 64 |
extensions = [ |
| 65 |
"sphinx.ext.autodoc", |
| 66 |
"sphinx.ext.intersphinx", |
| 67 |
"sphinx.ext.linkcode", |
| 68 |
"sphinx.ext.napoleon", |
| 69 |
"sphinx_copybutton", |
| 70 |
"sphinx_inline_tabs", |
| 71 |
"sphinxcontrib.spelling", |
| 72 |
"sphinxext.opengraph", |
| 73 |
] |
| 74 |
# It is currently inconvenient to install PyEnchant on Apple Silicon. |
| 75 |
try: |
| 76 |
import sphinxcontrib.spelling # noqa: F401 |
| 77 |
except ImportError: |
| 78 |
extensions.remove("sphinxcontrib.spelling") |
| 79 |
|
| 80 |
autodoc_typehints = "description" |
| 81 |
|
| 82 |
autodoc_typehints_description_target = "documented" |
| 83 |
|
| 84 |
# Workaround for https://github.com/sphinx-doc/sphinx/issues/9560 (fixed) |
| 85 |
# but still needed due to https://github.com/sphinx-doc/sphinx/pull/14171 |
| 86 |
# See reference/types.rst for details. |
| 87 |
from sphinx.domains.python import PythonDomain # noqa: E402 |
| 88 |
|
| 89 |
|
| 90 |
assert PythonDomain.object_types["data"].roles == ("data", "obj") |
| 91 |
PythonDomain.object_types["data"].roles = ("data", "class", "obj") |
| 92 |
|
| 93 |
# Workaround for https://github.com/sphinx-doc/sphinx/issues/10359 |
| 94 |
from sphinx.pycode import ModuleAnalyzer # noqa: E402 |
| 95 |
|
| 96 |
|
| 97 |
analyze_fn = ModuleAnalyzer.analyze |
| 98 |
|
| 99 |
|
| 100 |
def analyze_but_skip_overloads(self): |
| 101 |
result = analyze_fn(self) |
| 102 |
self.overloads = {} |
| 103 |
return result |
| 104 |
|
| 105 |
|
| 106 |
ModuleAnalyzer.analyze = analyze_but_skip_overloads |
| 107 |
|
| 108 |
intersphinx_mapping = { |
| 109 |
"python": ("https://docs.python.org/3", None), |
| 110 |
"sesame": ("https://django-sesame.readthedocs.io/en/stable/", None), |
| 111 |
"trio": ("https://trio.readthedocs.io/en/stable/", None), |
| 112 |
"werkzeug": ("https://werkzeug.palletsprojects.com/en/stable/", None), |
| 113 |
} |
| 114 |
|
| 115 |
spelling_show_suggestions = True |
| 116 |
|
| 117 |
# Add any paths that contain templates here, relative to this directory. |
| 118 |
templates_path = ["_templates"] |
| 119 |
|
| 120 |
# List of patterns, relative to source directory, that match files and |
| 121 |
# directories to ignore when looking for source files. |
| 122 |
# This pattern also affects html_static_path and html_extra_path. |
| 123 |
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] |
| 124 |
|
| 125 |
|
| 126 |
# Configure viewcode extension. |
| 127 |
|
| 128 |
code_url = f"https://github.com/python-websockets/websockets/blob/{commit}" |
| 129 |
|
| 130 |
|
| 131 |
def linkcode_resolve(domain, info): |
| 132 |
# Non-linkable objects from the starter kit in the tutorial. |
| 133 |
if domain == "js" or info["module"] == "connect4": |
| 134 |
return |
| 135 |
|
| 136 |
assert domain == "py", "expected only Python objects" |
| 137 |
|
| 138 |
mod = importlib.import_module(info["module"]) |
| 139 |
if "." in info["fullname"]: |
| 140 |
objname, attrname = info["fullname"].split(".") |
| 141 |
obj = getattr(mod, objname) |
| 142 |
try: |
| 143 |
# object is a method of a class |
| 144 |
obj = getattr(obj, attrname) |
| 145 |
except AttributeError: |
| 146 |
# object is an attribute of a class |
| 147 |
return None |
| 148 |
else: |
| 149 |
obj = getattr(mod, info["fullname"]) |
| 150 |
|
| 151 |
try: |
| 152 |
file = inspect.getsourcefile(obj) |
| 153 |
lines = inspect.getsourcelines(obj) |
| 154 |
except TypeError: |
| 155 |
# e.g. object is a typing.Union |
| 156 |
return None |
| 157 |
file = os.path.relpath(file, os.path.abspath("..")) |
| 158 |
if not file.startswith("src/websockets"): |
| 159 |
# e.g. object is a typing.NewType |
| 160 |
return None |
| 161 |
start, end = lines[1], lines[1] + len(lines[0]) - 1 |
| 162 |
|
| 163 |
return f"{code_url}/{file}#L{start}-L{end}" |
| 164 |
|
| 165 |
|
| 166 |
# Configure opengraph extension |
| 167 |
|
| 168 |
# Social cards don't support the SVG logo. Also, the text preview looks bad. |
| 169 |
ogp_social_cards = {"enable": False} |
| 170 |
|
| 171 |
|
| 172 |
# -- Options for HTML output ------------------------------------------------- |
| 173 |
|
| 174 |
# The theme to use for HTML and HTML Help pages. See the documentation for |
| 175 |
# a list of builtin themes. |
| 176 |
html_theme = "furo" |
| 177 |
|
| 178 |
html_theme_options = { |
| 179 |
"light_css_variables": { |
| 180 |
"color-brand-primary": "#306998", # blue from logo |
| 181 |
"color-brand-content": "#0b487a", # blue more saturated and less dark |
| 182 |
}, |
| 183 |
"dark_css_variables": { |
| 184 |
"color-brand-primary": "#ffd43bcc", # yellow from logo, more muted than content |
| 185 |
"color-brand-content": "#ffd43bd9", # yellow from logo, transparent like text |
| 186 |
}, |
| 187 |
"sidebar_hide_name": True, |
| 188 |
} |
| 189 |
|
| 190 |
html_logo = "_static/websockets.svg" |
| 191 |
|
| 192 |
html_favicon = "_static/favicon.ico" |
| 193 |
|
| 194 |
# Add any paths that contain custom static files (such as style sheets) here, |
| 195 |
# relative to this directory. They are copied after the builtin static files, |
| 196 |
# so a file named "default.css" will overwrite the builtin "default.css". |
| 197 |
html_static_path = ["_static"] |
| 198 |
|
| 199 |
html_copy_source = False |
| 200 |
|
| 201 |
html_show_sphinx = False |