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

chore: simpler tox.ini, declare dev deps in pyproject.toml #1205

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
name: Unit tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- "3.8"
Expand Down
24 changes: 9 additions & 15 deletions juju/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .facade_versions import client_facade_versions, known_unsupported_facades

SpecifiedFacades: TypeAlias = "dict[str, dict[Literal['versions'], Sequence[int]]]"
_WebSocket: TypeAlias = "websockets.legacy.client.WebSocketClientProtocol"
_WebSocket: TypeAlias = websockets.WebSocketClientProtocol

LEVELS = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR"]
log = logging.getLogger("juju.client.connection")
Expand Down Expand Up @@ -291,7 +291,7 @@ def is_using_old_client(self):
def is_open(self):
return self.monitor.status == Monitor.CONNECTED

def _get_ssl(self, cert=None):
def _get_ssl(self, cert: str | None = None) -> ssl.SSLContext:
context = ssl.create_default_context(
purpose=ssl.Purpose.SERVER_AUTH, cadata=cert
)
Expand All @@ -305,7 +305,9 @@ def _get_ssl(self, cert=None):
context.check_hostname = False
return context

async def _open(self, endpoint, cacert) -> tuple[_WebSocket, str, str, str]:
async def _open(
self, endpoint: str, cacert: str
) -> tuple[_WebSocket, str, str, str]:
if self.is_debug_log_connection:
assert self.uuid
url = f"wss://user-{self.username}:{self.password}@{endpoint}/model/{self.uuid}/log"
Expand All @@ -323,10 +325,6 @@ async def _open(self, endpoint, cacert) -> tuple[_WebSocket, str, str, str]:
sock = self.proxy.socket()
server_hostname = "juju-app"

def _exit_tasks():
for task in jasyncio.all_tasks():
task.cancel()

return (
(
await websockets.connect(
Expand All @@ -342,7 +340,7 @@ def _exit_tasks():
cacert,
)

async def close(self, to_reconnect=False):
async def close(self, to_reconnect: bool = False):
if not self._ws:
return
self.monitor.close_called.set()
Expand Down Expand Up @@ -380,11 +378,7 @@ async def close(self, to_reconnect=False):

async def _recv(self, request_id: int) -> dict[str, Any]:
if not self.is_open:
raise websockets.exceptions.ConnectionClosed(
websockets.frames.Close(
websockets.frames.CloseCode.NORMAL_CLOSURE, "websocket closed"
)
)
raise websockets.exceptions.ConnectionClosedOK(None, None)
try:
return await self.messages.get(request_id)
except GeneratorExit:
Expand Down Expand Up @@ -626,7 +620,7 @@ async def rpc(

return result

def _http_headers(self):
def _http_headers(self) -> dict[str, str]:
"""Return dictionary of http headers necessary for making an http
connection to the endpoint of this Connection.

Expand All @@ -640,7 +634,7 @@ def _http_headers(self):
token = base64.b64encode(creds.encode())
return {"Authorization": f"Basic {token.decode()}"}

def https_connection(self):
def https_connection(self) -> tuple[HTTPSConnection, dict[str, str], str]:
"""Return an https connection to this Connection's endpoint.

Returns a 3-tuple containing::
Expand Down
3 changes: 2 additions & 1 deletion juju/client/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
self.model_name = None
self.jujudata = jujudata or FileJujuData()

def is_connected(self):
def is_connected(self) -> bool:
"""Report whether there is a currently connected controller or not"""
return self._connection is not None

Expand All @@ -60,6 +60,7 @@ def connection(self) -> Connection:
"""
if not self.is_connected():
raise NoConnectionException("not connected")
assert self._connection
return self._connection

async def connect(self, **kwargs):
Expand Down
Loading
Loading