Skip to content

Commit 4b2a338

Browse files
committed
Add comprehensive docstrings for public API attributes
Added detailed Sphinx-compatible docstrings for the following public API attributes to improve documentation and developer experience: 1. autobahn.websocket.HAS_NVX - Explains build-time NVX availability check - Documents what NVX provides (UTF-8 validation, XOR masking) - Clarifies independence from AUTOBAHN_USE_NVX runtime setting - Includes usage example and cross-reference to USES_NVX 2. autobahn.websocket.USES_NVX - Explains runtime NVX usage decision - Documents interaction between build-time availability and runtime config - Provides complete AUTOBAHN_USE_NVX environment variable reference - Includes scenario examples and cross-reference to HAS_NVX 3. autobahn.twisted.__ident__ - Enhanced existing brief docstring with comprehensive documentation - Documents format variations (with/without NVX acceleration) - Explains usage in protocol handshakes (WebSocket Upgrade, WAMP HELLO) - Provides example values for different configurations - Cross-references asyncio.__ident__ and USES_NVX 4. autobahn.asyncio.__ident__ - Enhanced existing brief docstring with comprehensive documentation - Documents format variations (with/without NVX acceleration) - Explains usage in protocol handshakes (WebSocket Upgrade, WAMP HELLO) - Notes difference from Twisted variant (no asyncio version number) - Provides example values for different configurations - Cross-references twisted.__ident__ and USES_NVX All docstrings follow reStructuredText format for proper Sphinx rendering in Read the Docs documentation. This is a documentation-only change with no functional modifications. Related: This is a safe change to trigger final workflow testing before merging rel_v25.10.2 to master (addresses issues #1735, #1714).
1 parent e431e88 commit 4b2a338

File tree

3 files changed

+135
-2
lines changed

3 files changed

+135
-2
lines changed

autobahn/asyncio/__init__.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,41 @@
6161
__ident__ = "Autobahn/{}-asyncio-{}/{}".format(
6262
autobahn.__version__, platform.python_implementation(), platform.python_version()
6363
)
64+
6465
"""
65-
AutobahnPython library implementation (eg. "Autobahn/0.13.0-asyncio-CPython/3.5.1")
66+
Identification string for the Autobahn|Python asyncio backend.
67+
68+
This string identifies the library version, networking framework, and runtime
69+
environment. It's commonly used in protocol handshakes (e.g., WebSocket Upgrade
70+
headers, WAMP HELLO metadata) to identify the client/server implementation.
71+
72+
Format with NVX acceleration enabled::
73+
74+
"Autobahn/{version}-NVXCFFI/{cffi_version}-asyncio-{python_impl}/{python_version}"
75+
76+
Format without NVX acceleration::
77+
78+
"Autobahn/{version}-asyncio-{python_impl}/{python_version}"
79+
80+
The presence of ``NVXCFFI`` in the identification string indicates that NVX
81+
(Native Vector Extensions) native acceleration is enabled, providing high-performance
82+
UTF-8 validation and XOR masking using SIMD instructions.
83+
84+
Note that asyncio is built into Python's standard library (since Python 3.4),
85+
so no separate asyncio version is included in the identification string (unlike
86+
the Twisted backend which includes the Twisted version).
87+
88+
:type: str
89+
90+
Example values::
91+
92+
# With NVX acceleration on CPython
93+
"Autobahn/25.10.2-NVXCFFI/1.15.1-asyncio-CPython/3.11.9"
94+
95+
# Without NVX acceleration on PyPy
96+
"Autobahn/25.10.2-asyncio-PyPy/7.3.16"
97+
98+
See Also:
99+
:data:`autobahn.twisted.__ident__` - Identification string for Twisted backend
100+
:data:`autobahn.websocket.USES_NVX` - Whether NVX acceleration is enabled
66101
"""

autobahn/twisted/__init__.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,37 @@
8080
platform.python_implementation(),
8181
platform.python_version(),
8282
)
83+
8384
"""
84-
AutobahnPython library implementation (eg. "Autobahn/0.13.0-Twisted/15.5.0-CPython/3.5.1")
85+
Identification string for the Autobahn|Python Twisted backend.
86+
87+
This string identifies the library version, networking framework, and runtime
88+
environment. It's commonly used in protocol handshakes (e.g., WebSocket Upgrade
89+
headers, WAMP HELLO metadata) to identify the client/server implementation.
90+
91+
Format with NVX acceleration enabled::
92+
93+
"Autobahn/{version}-NVXCFFI/{cffi_version}-Twisted/{twisted_version}-{python_impl}/{python_version}"
94+
95+
Format without NVX acceleration::
96+
97+
"Autobahn/{version}-Twisted/{twisted_version}-{python_impl}/{python_version}"
98+
99+
The presence of ``NVXCFFI`` in the identification string indicates that NVX
100+
(Native Vector Extensions) native acceleration is enabled, providing high-performance
101+
UTF-8 validation and XOR masking using SIMD instructions.
102+
103+
:type: str
104+
105+
Example values::
106+
107+
# With NVX acceleration on CPython
108+
"Autobahn/25.10.2-NVXCFFI/1.15.1-Twisted/24.7.0-CPython/3.11.9"
109+
110+
# Without NVX acceleration on PyPy
111+
"Autobahn/25.10.2-Twisted/24.7.0-PyPy/7.3.16"
112+
113+
See Also:
114+
:data:`autobahn.asyncio.__ident__` - Identification string for asyncio backend
115+
:data:`autobahn.websocket.USES_NVX` - Whether NVX acceleration is enabled
85116
"""

autobahn/websocket/__init__.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,37 @@
4848
except ImportError:
4949
# NVX not available (not built or CFFI compilation failed)
5050
pass
51+
5152
HAS_NVX = _has_nvx
53+
"""
54+
Boolean flag indicating whether NVX (Native Vector Extensions) native acceleration
55+
modules are available in this installation.
56+
57+
This is a build-time capability check - it's ``True`` if the NVX native extensions
58+
were successfully compiled and can be imported, ``False`` otherwise.
59+
60+
NVX provides native implementations for performance-critical WebSocket operations:
61+
62+
* UTF-8 validation using SIMD instructions
63+
* XOR masking using vectorized operations
64+
65+
The value of ``HAS_NVX`` is independent of the runtime setting ``AUTOBAHN_USE_NVX``.
66+
To check if NVX is actually being used at runtime, see :data:`USES_NVX`.
67+
68+
:type: bool
69+
70+
Example::
71+
72+
from autobahn.websocket import HAS_NVX
73+
74+
if HAS_NVX:
75+
print("NVX native acceleration is available")
76+
else:
77+
print("NVX not built - using pure Python implementations")
78+
79+
See Also:
80+
:data:`USES_NVX` - Whether NVX is actually enabled at runtime
81+
"""
5282

5383
# Step 2: Parse AUTOBAHN_USE_NVX environment variable
5484
env_val = os.environ.get("AUTOBAHN_USE_NVX", "").strip().lower()
@@ -88,6 +118,43 @@
88118
# Case 5: Default behavior - use NVX if available
89119
USES_NVX = HAS_NVX
90120

121+
"""
122+
Boolean flag indicating whether NVX (Native Vector Extensions) native acceleration
123+
is actually being used at runtime.
124+
125+
This reflects the runtime configuration after considering both:
126+
127+
* **Build-time availability** (:data:`HAS_NVX`) - Were NVX modules compiled?
128+
* **Runtime configuration** (``AUTOBAHN_USE_NVX`` environment variable) - Is NVX enabled?
129+
130+
Possible scenarios:
131+
132+
* ``USES_NVX = True``: NVX is built AND enabled (default when available)
133+
* ``USES_NVX = False``: Either NVX not built OR explicitly disabled via ``AUTOBAHN_USE_NVX=0``
134+
135+
Control NVX at runtime using the ``AUTOBAHN_USE_NVX`` environment variable:
136+
137+
* ``AUTOBAHN_USE_NVX=1`` - Force enable (raises error if not built)
138+
* ``AUTOBAHN_USE_NVX=0`` - Force disable (falls back to pure Python)
139+
* Unset or empty - Auto-enable if available (default)
140+
141+
:type: bool
142+
143+
Example::
144+
145+
from autobahn.websocket import USES_NVX, HAS_NVX
146+
147+
if USES_NVX:
148+
print("Using NVX native acceleration for WebSocket operations")
149+
elif HAS_NVX:
150+
print("NVX available but disabled (AUTOBAHN_USE_NVX=0)")
151+
else:
152+
print("NVX not built - using pure Python implementations")
153+
154+
See Also:
155+
:data:`HAS_NVX` - Whether NVX was built and is available
156+
"""
157+
91158
# ============================================================================
92159
# End of NVX Runtime Configuration
93160
# ============================================================================

0 commit comments

Comments
 (0)