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

fix: deprecated websockets API usage and remove upper bound for that dep #1216

Merged
merged 3 commits into from
Nov 27, 2024
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
5 changes: 2 additions & 3 deletions juju/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def status(self):
and connection._receiver_task.cancelled()
)

if stopped or not connection._ws.open:
if stopped or connection._ws.state is not websockets.protocol.State.OPEN:
return self.ERROR

# everything is fine!
Expand Down Expand Up @@ -357,8 +357,7 @@ async def close(self, to_reconnect: bool = False):
tasks_need_to_be_gathered.append(self._debug_log_task)
self._debug_log_task.cancel()

if self._ws and not self._ws.closed:
await self._ws.close()
await self._ws.close()

if not to_reconnect:
try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [
"macaroonbakery>=1.1,<2.0",
"pyRFC3339>=1.0,<2.0",
"pyyaml>=5.1.2",
"websockets>=13.0.1,<14.0",
"websockets>=13.0.1",
"paramiko>=2.4.0",
"pyasn1>=0.4.4",
"toposort>=1.5,<2",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"macaroonbakery>=1.1,<2.0",
"pyRFC3339>=1.0,<2.0",
"pyyaml>=5.1.2",
"websockets>=13.0.1,<14.0",
"websockets>=13.0.1",
"paramiko>=2.4.0",
"pyasn1>=0.4.4",
"toposort>=1.5,<2",
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from unittest import mock

import pytest
import websockets
from websockets.exceptions import ConnectionClosed

from juju.client.connection import Connection
Expand All @@ -17,8 +18,7 @@ class WebsocketMock:
def __init__(self, responses):
super().__init__()
self.responses = deque(responses)
self.open = True
self.closed = False
self.state = websockets.protocol.State.OPEN

async def send(self, message):
pass
Expand All @@ -30,8 +30,7 @@ async def recv(self):
return json.dumps(self.responses.popleft())

async def close(self):
self.open = False
self.closed = True
pass


async def test_out_of_order():
Expand Down
Loading