Skip to content

Commit 082e26a

Browse files
[DPE-3881] Use ruff as a linter and formatter (#489)
* Use ruff as a linter and formatter * Comment all ignore rules * Bump mysql and tls libs libpatch
1 parent 643084e commit 082e26a

27 files changed

+383
-704
lines changed

lib/charms/mysql/v0/async_replication.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# The unique Charmhub library identifier, never change it
5555
LIBID = "4de21f1a022c4e2c87ac8e672ec16f6a"
5656
LIBAPI = 0
57-
LIBPATCH = 5
57+
LIBPATCH = 6
5858

5959
RELATION_OFFER = "replication-offer"
6060
RELATION_CONSUMER = "replication"
@@ -778,9 +778,10 @@ def _on_consumer_changed(self, event): # noqa: C901
778778
logger.debug("Recreating cluster prior to sync credentials")
779779
self._charm.create_cluster()
780780
# (re)set flags
781-
self._charm.app_peer_data.update(
782-
{"removed-from-cluster-set": "", "rejoin-secondaries": "true"}
783-
)
781+
self._charm.app_peer_data.update({
782+
"removed-from-cluster-set": "",
783+
"rejoin-secondaries": "true",
784+
})
784785
event.defer()
785786
return
786787
if not self._charm.cluster_fully_initialized:

lib/charms/mysql/v0/backups.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def is_unit_blocked(self) -> bool:
9999

100100
# Increment this PATCH version before using `charmcraft publish-lib` or reset
101101
# to 0 if you are raising the major API version
102-
LIBPATCH = 10
102+
LIBPATCH = 11
103103

104104

105105
if typing.TYPE_CHECKING:
@@ -314,11 +314,9 @@ def _on_create_backup(self, event: ActionEvent) -> None:
314314
return
315315

316316
logger.info(f"Backup succeeded: with backup-id {datetime_backup_requested}")
317-
event.set_results(
318-
{
319-
"backup-id": datetime_backup_requested,
320-
}
321-
)
317+
event.set_results({
318+
"backup-id": datetime_backup_requested,
319+
})
322320
self.charm._on_update_status(None)
323321

324322
def _can_unit_perform_backup(self) -> Tuple[bool, Optional[str]]:
@@ -538,11 +536,9 @@ def _on_restore(self, event: ActionEvent) -> None:
538536
return
539537

540538
logger.info("Restore succeeded")
541-
event.set_results(
542-
{
543-
"completed": "ok",
544-
}
545-
)
539+
event.set_results({
540+
"completed": "ok",
541+
})
546542
# update status as soon as possible
547543
self.charm._on_update_status(None)
548544

lib/charms/mysql/v0/mysql.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def wait_until_mysql_connection(self) -> None:
128128
# Increment this major API version when introducing breaking changes
129129
LIBAPI = 0
130130

131-
LIBPATCH = 64
131+
LIBPATCH = 65
132132

133133
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
134134
UNIT_ADD_LOCKNAME = "unit-add"
@@ -421,9 +421,7 @@ def __init__(self, *args):
421421
super().__init__(*args)
422422

423423
# disable support
424-
disable_file = Path(
425-
f"{os.environ.get('CHARM_DIR')}/disable"
426-
) # pyright: ignore [reportArgumentType]
424+
disable_file = Path(f"{os.environ.get('CHARM_DIR')}/disable") # pyright: ignore [reportArgumentType]
427425
if disable_file.exists():
428426
logger.warning(
429427
f"\n\tDisable file `{disable_file.resolve()}` found, the charm will skip all events."
@@ -539,19 +537,15 @@ def _get_cluster_status(self, event: ActionEvent) -> None:
539537
status = self._mysql.get_cluster_status()
540538

541539
if status:
542-
event.set_results(
543-
{
544-
"success": True,
545-
"status": status,
546-
}
547-
)
540+
event.set_results({
541+
"success": True,
542+
"status": status,
543+
})
548544
else:
549-
event.set_results(
550-
{
551-
"success": False,
552-
"message": "Failed to read cluster status. See logs for more information.",
553-
}
554-
)
545+
event.set_results({
546+
"success": False,
547+
"message": "Failed to read cluster status. See logs for more information.",
548+
})
555549

556550
def _recreate_cluster(self, event: ActionEvent) -> None:
557551
"""Action used to recreate the cluster, for special cases."""
@@ -564,9 +558,9 @@ def _recreate_cluster(self, event: ActionEvent) -> None:
564558
del self.app_peer_data["removed-from-cluster-set"]
565559

566560
# reset cluster-set-name to config or previous value
567-
hash = self.generate_random_hash()
561+
random_hash = self.generate_random_hash()
568562
self.app_peer_data["cluster-set-domain-name"] = self.model.config.get(
569-
"cluster-set-name", f"cluster-set-{hash}"
563+
"cluster-set-name", f"cluster-set-{random_hash}"
570564
)
571565

572566
logger.info("Recreating cluster")
@@ -1226,12 +1220,10 @@ def configure_instance(self, create_cluster_admin: bool = True) -> None:
12261220
}
12271221

12281222
if create_cluster_admin:
1229-
options.update(
1230-
{
1231-
"clusterAdmin": self.cluster_admin_user,
1232-
"clusterAdminPassword": self.cluster_admin_password,
1233-
}
1234-
)
1223+
options.update({
1224+
"clusterAdmin": self.cluster_admin_user,
1225+
"clusterAdminPassword": self.cluster_admin_password,
1226+
})
12351227

12361228
configure_instance_command = (
12371229
f"dba.configure_instance('{self.server_config_user}:{self.server_config_password}@{self.instance_address}', {json.dumps(options)})",
@@ -1805,15 +1797,15 @@ def execute_remove_instance(
18051797
reraise=True,
18061798
wait=wait_random(min=4, max=30),
18071799
)
1808-
def remove_instance(self, unit_label: str, lock_instance: Optional[str] = None) -> None:
1800+
def remove_instance(self, unit_label: str, lock_instance: Optional[str] = None) -> None: # noqa: C901
18091801
"""Remove instance from the cluster.
18101802
18111803
This method is called from each unit being torn down, thus we must obtain
18121804
locks on the cluster primary. There is a retry mechanism for any issues
18131805
obtaining the lock, removing instances/dissolving the cluster, or releasing
18141806
the lock.
18151807
"""
1816-
remaining_cluster_member_addresses = list()
1808+
remaining_cluster_member_addresses = []
18171809
skip_release_lock = False
18181810
try:
18191811
# Get the cluster primary's address to direct lock acquisition request to.
@@ -2818,9 +2810,9 @@ def flush_mysql_logs(self, logs_type: Union[MySQLTextLogs, list[MySQLTextLogs]])
28182810
]
28192811

28202812
if isinstance(logs_type, list):
2821-
flush_logs_commands.extend(
2822-
[f"session.run_sql('FLUSH {log.value}')" for log in logs_type]
2823-
)
2813+
flush_logs_commands.extend([
2814+
f"session.run_sql('FLUSH {log.value}')" for log in logs_type
2815+
])
28242816
else:
28252817
flush_logs_commands.append(f'session.run_sql("FLUSH {logs_type.value}")') # type: ignore
28262818

lib/charms/mysql/v0/s3_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
"""S3 helper functions for the MySQL charms."""
16+
1617
import base64
1718
import logging
1819
import tempfile
@@ -31,7 +32,7 @@
3132

3233
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3334
# to 0 if you are raising the major API version
34-
LIBPATCH = 8
35+
LIBPATCH = 9
3536

3637
# botocore/urllib3 clutter the logs when on debug
3738
logging.getLogger("botocore").setLevel(logging.WARNING)

lib/charms/mysql/v0/tls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
2020
"""
2121

22-
2322
import base64
2423
import logging
2524
import re
@@ -52,7 +51,7 @@
5251

5352
LIBID = "eb73947deedd4380a3a90d527e0878eb"
5453
LIBAPI = 0
55-
LIBPATCH = 6
54+
LIBPATCH = 7
5655

5756
SCOPE = "unit"
5857

0 commit comments

Comments
 (0)