Skip to content

Commit 50199e2

Browse files
committed
chore: fix client and connection, disable warnings for the generated code
1 parent 9b45d8a commit 50199e2

5 files changed

Lines changed: 37 additions & 19 deletions

File tree

juju/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
if not a.startswith("_"):
3333
setattr(c_type, a, getattr(o_type, a))
3434

35-
from ._client import * # noqa, isort:skip
35+
from ._client import * # noqa: F403,E402, isort:skip

juju/client/codegen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def write(self, msg, depth=0):
2222
prefix = self.INDENT * depth
2323
msg = indent(msg, prefix)
2424

25-
return super(CodeWriter, self).write(msg)
25+
return super().write(msg)
2626

2727
def __str__(self):
28-
return super(CodeWriter, self).getvalue()
28+
return super().getvalue()
2929

3030

3131
class Capture(defaultdict):
@@ -35,7 +35,7 @@ class Capture(defaultdict):
3535
"""
3636

3737
def __init__(self, default_factory=CodeWriter, *args, **kwargs):
38-
super(Capture, self).__init__(default_factory, *args, **kwargs)
38+
super().__init__(default_factory, *args, **kwargs)
3939

4040
def clear(self, name):
4141
"""Reset one of the keys in this class, if it exists.

juju/client/connection.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from .facade_versions import client_facade_versions, known_unsupported_facades
2525

26+
LEVELS = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR"]
2627
log = logging.getLogger("juju.client.connection")
2728

2829

@@ -240,7 +241,7 @@ async def connect(
240241
if isinstance(endpoint, str)
241242
else [(e, cacert) for e in endpoint]
242243
)
243-
lastError = None
244+
last_error = None
244245
for _ep in _endpoints:
245246
try:
246247
if self.is_debug_log_connection:
@@ -251,14 +252,14 @@ async def connect(
251252
await self._connect_with_redirect([_ep])
252253
return self
253254
except ssl.SSLError as e:
254-
lastError = e
255+
last_error = e
255256
continue
256257
except OSError as e:
257258
logging.debug(f"Cannot access endpoint {_ep}: {e.strerror}")
258-
lastError = e
259+
last_error = e
259260
continue
260-
if lastError is not None:
261-
raise lastError
261+
if last_error is not None:
262+
raise last_error
262263
raise Exception("Unable to connect to websocket")
263264

264265
@property
@@ -407,7 +408,6 @@ def debug_log_filter_write(self, result):
407408
and (included_entities == [] or entity in included_entities)
408409
)
409410

410-
LEVELS = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR"]
411411
log_level = self.debug_log_params["level"]
412412

413413
if log_level != "" and log_level not in LEVELS:
@@ -595,10 +595,11 @@ async def rpc(self, msg, encoder=None):
595595
# Perhaps JujuError should return all the results including
596596
# errors, or perhaps a keyword parameter to the rpc method
597597
# could be added to trigger this behaviour.
598-
err_results = []
599-
for res in result["response"]["results"] or []:
600-
if res.get("error", {}).get("message"):
601-
err_results.append(res["error"]["message"])
598+
err_results = [
599+
res["error"]["message"]
600+
for res in (result["response"]["results"] or [])
601+
if res.get("error", {}).get("message")
602+
]
602603
if err_results:
603604
raise errors.JujuError(err_results)
604605

@@ -781,14 +782,14 @@ async def _connect_with_login(self, endpoints):
781782
# It's possible that we may get several discharge-required errors,
782783
# corresponding to different levels of authentication, so retry
783784
# a few times.
784-
for i in range(0, 2):
785+
for _ in range(0, 2):
785786
result = (await self.login())["response"]
786-
macaroonJSON = result.get("discharge-required")
787-
if macaroonJSON is None:
787+
macaroon_json = result.get("discharge-required")
788+
if macaroon_json is None:
788789
self.info = result
789790
success = True
790791
return result
791-
macaroon = bakery.Macaroon.from_dict(macaroonJSON)
792+
macaroon = bakery.Macaroon.from_dict(macaroon_json)
792793
self.bakery_client.handle_error(
793794
httpbakery.Error(
794795
code=httpbakery.ERR_DISCHARGE_REQUIRED,

juju/client/connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class NoConnectionException(Exception):
2727

2828

2929
class Connector:
30-
"""This class abstracts out a reconnectable client that can connect
30+
"""Abstracts out a reconnectable client that can connect
3131
to controllers and models found in the Juju data files.
3232
"""
3333

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,24 @@ ignore = [
131131
"UP031",
132132
]
133133

134+
134135
[tool.ruff.lint.per-file-ignores]
136+
"juju/client/_*.py" = [
137+
# Copyright
138+
"CPY001",
139+
# Codegen limitation: empty structs have empty docstrings.
140+
"D419",
141+
# CamelCase
142+
"N802",
143+
# star imports
144+
"F403",
145+
"F405",
146+
# FIXME: undefined FacadeVersions...
147+
# Is the class from _client.py intended?
148+
# How does login even work?
149+
"F821",
150+
]
151+
135152
"tests/*" = [
136153
# assert False to fail
137154
"B011",

0 commit comments

Comments
 (0)