Skip to content

Commit c9e3efd

Browse files
authored
feat: move websocket-client to extra dependency (#3123)
Also bump minimum version to that prescribed by #3022 Signed-off-by: Aarni Koskela <akx@iki.fi>
1 parent 4a88112 commit c9e3efd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

docker/api/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import requests
77
import requests.exceptions
8-
import websocket
98

109
from .. import auth
1110
from ..constants import (DEFAULT_NUM_POOLS, DEFAULT_NUM_POOLS_SSH,
@@ -309,7 +308,16 @@ def _attach_websocket(self, container, params=None):
309308
return self._create_websocket_connection(full_url)
310309

311310
def _create_websocket_connection(self, url):
312-
return websocket.create_connection(url)
311+
try:
312+
import websocket
313+
return websocket.create_connection(url)
314+
except ImportError as ie:
315+
raise DockerException(
316+
'The `websocket-client` library is required '
317+
'for using websocket connections. '
318+
'You can install the `docker` library '
319+
'with the [websocket] extra to install it.'
320+
) from ie
313321

314322
def _get_raw_response_socket(self, response):
315323
self._raise_for_status(response)

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
'packaging >= 14.0',
1414
'requests >= 2.26.0',
1515
'urllib3 >= 1.26.0',
16-
'websocket-client >= 0.32.0',
1716
]
1817

1918
extras_require = {
@@ -27,6 +26,9 @@
2726

2827
# Only required when connecting using the ssh:// protocol
2928
'ssh': ['paramiko>=2.4.3'],
29+
30+
# Only required when using websockets
31+
'websockets': ['websocket-client >= 1.3.0'],
3032
}
3133

3234
with open('./test-requirements.txt') as test_reqs_txt:

0 commit comments

Comments
 (0)