Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move websocket-client to extra dependency #3123

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docker/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import requests
import requests.exceptions
import websocket

from .. import auth
from ..constants import (DEFAULT_NUM_POOLS, DEFAULT_NUM_POOLS_SSH,
Expand Down Expand Up @@ -312,7 +311,16 @@ def _attach_websocket(self, container, params=None):
return self._create_websocket_connection(full_url)

def _create_websocket_connection(self, url):
return websocket.create_connection(url)
try:
import websocket
return websocket.create_connection(url)
except ImportError as ie:
raise DockerException(
'The `websocket-client` library is required '
'for using websocket connections. '
'You can install the `docker` library '
'with the [websocket] extra to install it.'
) from ie

def _get_raw_response_socket(self, response):
self._raise_for_status(response)
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
'packaging >= 14.0',
'requests >= 2.26.0',
'urllib3 >= 1.26.0',
'websocket-client >= 0.32.0',
]

extras_require = {
Expand All @@ -27,6 +26,9 @@

# Only required when connecting using the ssh:// protocol
'ssh': ['paramiko>=2.4.3'],

# Only required when using websockets
'websockets': ['websocket-client >= 1.3.0'],
}

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