diff options
author | joshua Watt <JPEWhacker@gmail.com> | 2024-05-02 12:35:16 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-08 14:51:44 +0100 |
commit | 23c5058707333a7c330075c247685ac05906d4b6 (patch) | |
tree | 66c1fb937c15c5f17a3f5f8e8b5e76c262997a8e | |
parent | aff8b073341513394c64c8cb3045d2450786320b (diff) | |
download | poky-23c5058707333a7c330075c247685ac05906d4b6.tar.gz |
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 <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/asyncrpc/client.py | 22 |
1 files changed, 22 insertions, 0 deletions
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 | |||
24 | ADDR_TYPE_TCP = 1 | 24 | ADDR_TYPE_TCP = 1 |
25 | ADDR_TYPE_WS = 2 | 25 | ADDR_TYPE_WS = 2 |
26 | 26 | ||
27 | WEBSOCKETS_MIN_VERSION = (9, 1) | ||
28 | |||
29 | |||
27 | def parse_address(addr): | 30 | def parse_address(addr): |
28 | if addr.startswith(UNIX_PREFIX): | 31 | if addr.startswith(UNIX_PREFIX): |
29 | return (ADDR_TYPE_UNIX, (addr[len(UNIX_PREFIX) :],)) | 32 | return (ADDR_TYPE_UNIX, (addr[len(UNIX_PREFIX) :],)) |
@@ -39,6 +42,7 @@ def parse_address(addr): | |||
39 | 42 | ||
40 | return (ADDR_TYPE_TCP, (host, int(port))) | 43 | return (ADDR_TYPE_TCP, (host, int(port))) |
41 | 44 | ||
45 | |||
42 | class AsyncClient(object): | 46 | class AsyncClient(object): |
43 | def __init__( | 47 | def __init__( |
44 | self, | 48 | self, |
@@ -86,6 +90,24 @@ class AsyncClient(object): | |||
86 | async def connect_websocket(self, uri): | 90 | async def connect_websocket(self, uri): |
87 | import websockets | 91 | import websockets |
88 | 92 | ||
93 | try: | ||
94 | version = tuple( | ||
95 | int(v) | ||
96 | for v in websockets.__version__.split(".")[ | ||
97 | 0 : len(WEBSOCKETS_MIN_VERSION) | ||
98 | ] | ||
99 | ) | ||
100 | except ValueError: | ||
101 | raise ImportError( | ||
102 | f"Unable to parse websockets version '{websockets.__version__}'" | ||
103 | ) | ||
104 | |||
105 | if version < WEBSOCKETS_MIN_VERSION: | ||
106 | min_ver_str = ".".join(str(v) for v in WEBSOCKETS_MIN_VERSION) | ||
107 | raise ImportError( | ||
108 | f"Websockets version {websockets.__version__} is less than minimum required version {min_ver_str}" | ||
109 | ) | ||
110 | |||
89 | async def connect_sock(): | 111 | async def connect_sock(): |
90 | websocket = await websockets.connect(uri, ping_interval=None) | 112 | websocket = await websockets.connect(uri, ping_interval=None) |
91 | return WebsocketConnection(websocket, self.timeout) | 113 | return WebsocketConnection(websocket, self.timeout) |