From 23c5058707333a7c330075c247685ac05906d4b6 Mon Sep 17 00:00:00 2001 From: joshua Watt Date: Thu, 2 May 2024 12:35:16 -0600 Subject: bitbake: asyncrpc: Check websockets version 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 (Bitbake rev: 330ea6914aad65dc8b34c986c44779820c392f03) Signed-off-by: Joshua Watt Signed-off-by: Richard Purdie --- bitbake/lib/bb/asyncrpc/client.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bitbake/lib/bb/asyncrpc/client.py b/bitbake/lib/bb/asyncrpc/client.py index a350b4fb12..65f3f8964d 100644 --- a/bitbake/lib/bb/asyncrpc/client.py +++ b/bitbake/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) -- cgit v1.2.3-54-g00ecf