aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoshua Watt <JPEWhacker@gmail.com>2024-05-02 12:35:16 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-05-02 22:02:03 +0100
commit7fd14bc1b9fc7f63187ecb8fddb479a69fe82190 (patch)
tree37d53bcd890a4230e1d2a0ea21706b226cf35a6d
parent8db7c22129b1f56770809703f94e2b26c0a3e1d3 (diff)
downloadbitbake-master-next.tar.gz
asyncrpc: Check websockets versionmaster-next
Checks that the minimum version of the websockets module is present, and if not raises an ImportError. This allows the user to get earlier feedback if using websockets is going to succeed Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/asyncrpc/client.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/bb/asyncrpc/client.py b/lib/bb/asyncrpc/client.py
index a350b4fb1..65f3f8964 100644
--- a/lib/bb/asyncrpc/client.py
+++ b/lib/bb/asyncrpc/client.py
@@ -24,6 +24,9 @@ ADDR_TYPE_UNIX = 0
ADDR_TYPE_TCP = 1
ADDR_TYPE_WS = 2
+WEBSOCKETS_MIN_VERSION = (9, 1)
+
+
def parse_address(addr):
if addr.startswith(UNIX_PREFIX):
return (ADDR_TYPE_UNIX, (addr[len(UNIX_PREFIX) :],))
@@ -39,6 +42,7 @@ def parse_address(addr):
return (ADDR_TYPE_TCP, (host, int(port)))
+
class AsyncClient(object):
def __init__(
self,
@@ -86,6 +90,24 @@ class AsyncClient(object):
async def connect_websocket(self, uri):
import websockets
+ try:
+ version = tuple(
+ int(v)
+ for v in websockets.__version__.split(".")[
+ 0 : len(WEBSOCKETS_MIN_VERSION)
+ ]
+ )
+ except ValueError:
+ raise ImportError(
+ f"Unable to parse websockets version '{websockets.__version__}'"
+ )
+
+ if version < WEBSOCKETS_MIN_VERSION:
+ min_ver_str = ".".join(str(v) for v in WEBSOCKETS_MIN_VERSION)
+ raise ImportError(
+ f"Websockets version {websockets.__version__} is less than minimum required version {min_ver_str}"
+ )
+
async def connect_sock():
websocket = await websockets.connect(uri, ping_interval=None)
return WebsocketConnection(websocket, self.timeout)