summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/third_party/websockets/docs/conf.py
blob: 9d61dc717369b49fc05801872e12ae5dd137a9c3 (plain)
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
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import datetime
import importlib
import inspect
import os
import subprocess
import sys

# -- Path setup --------------------------------------------------------------

# 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.join(os.path.abspath(".."), "src"))


# -- Project information -----------------------------------------------------

project = "websockets"
copyright = f"2013-{datetime.date.today().year}, Aymeric Augustin and contributors"
author = "Aymeric Augustin"

from websockets.version import tag as version, version as release


# -- General configuration ---------------------------------------------------

nitpicky = True

nitpick_ignore = [
    # topics/design.rst discusses undocumented APIs
    ("py:meth", "client.WebSocketClientProtocol.handshake"),
    ("py:meth", "server.WebSocketServerProtocol.handshake"),
    ("py:attr", "legacy.protocol.WebSocketCommonProtocol.is_client"),
    ("py:attr", "legacy.protocol.WebSocketCommonProtocol.messages"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.close_connection"),
    ("py:attr", "legacy.protocol.WebSocketCommonProtocol.close_connection_task"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.keepalive_ping"),
    ("py:attr", "legacy.protocol.WebSocketCommonProtocol.keepalive_ping_task"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.transfer_data"),
    ("py:attr", "legacy.protocol.WebSocketCommonProtocol.transfer_data_task"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.connection_open"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.ensure_open"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.fail_connection"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.connection_lost"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.read_message"),
    ("py:meth", "legacy.protocol.WebSocketCommonProtocol.write_frame"),
]

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.intersphinx",
    "sphinx.ext.linkcode",
    "sphinx.ext.napoleon",
    "sphinx_copybutton",
    "sphinx_inline_tabs",
    "sphinxcontrib.spelling",
    "sphinxcontrib_trio",
    "sphinxext.opengraph",
]
# It is currently inconvenient to install PyEnchant on Apple Silicon.
try:
    import sphinxcontrib.spelling
except ImportError:
    extensions.remove("sphinxcontrib.spelling")

autodoc_typehints = "description"

autodoc_typehints_description_target = "documented"

# Workaround for https://github.com/sphinx-doc/sphinx/issues/9560
from sphinx.domains.python import PythonDomain

assert PythonDomain.object_types["data"].roles == ("data", "obj")
PythonDomain.object_types["data"].roles = ("data", "class", "obj")

intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}

spelling_show_suggestions = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# Configure viewcode extension.
from websockets.version import commit

code_url = f"https://github.com/python-websockets/websockets/blob/{commit}"

def linkcode_resolve(domain, info):
    # Non-linkable objects from the starter kit in the tutorial.
    if domain == "js" or info["module"] == "connect4":
        return

    assert domain == "py", "expected only Python objects"

    mod = importlib.import_module(info["module"])
    if "." in info["fullname"]:
        objname, attrname = info["fullname"].split(".")
        obj = getattr(mod, objname)
        try:
            # object is a method of a class
            obj = getattr(obj, attrname)
        except AttributeError:
            # object is an attribute of a class
            return None
    else:
        obj = getattr(mod, info["fullname"])

    try:
        file = inspect.getsourcefile(obj)
        lines = inspect.getsourcelines(obj)
    except TypeError:
        # e.g. object is a typing.Union
        return None
    file = os.path.relpath(file, os.path.abspath(".."))
    if not file.startswith("src/websockets"):
        # e.g. object is a typing.NewType
        return None
    start, end = lines[1], lines[1] + len(lines[0]) - 1

    return f"{code_url}/{file}#L{start}-L{end}"

# Configure opengraph extension

# Social cards don't support the SVG logo. Also, the text preview looks bad.
ogp_social_cards = {"enable": False}


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
html_theme = "furo"

html_theme_options = {
    "light_css_variables": {
        "color-brand-primary": "#306998",  # blue from logo
        "color-brand-content": "#0b487a",  # blue more saturated and less dark
    },
    "dark_css_variables": {
        "color-brand-primary": "#ffd43bcc",  # yellow from logo, more muted than content
        "color-brand-content": "#ffd43bd9",  # yellow from logo, transparent like text
    },
    "sidebar_hide_name": True,
}

html_logo = "_static/websockets.svg"

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"]

html_copy_source = False

html_show_sphinx = False