Skip to content

Commit

Permalink
Even more linters
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Sep 2, 2024
1 parent 4437277 commit 25c942a
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pythonpath = [
# Formatting tools configuration
[tool.black]
line-length = 99
target-version = ["py38"]
target-version = ["py310"]

# Linting tools configuration
[tool.ruff]
Expand All @@ -109,7 +109,7 @@ line-length = 99

[tool.ruff.lint]
explicit-preview-rules = true
select = ["A", "E", "W", "F", "C", "N", "D", "I001", "CPY001", "SIM"]
select = ["A", "E", "W", "F", "C", "N", "D", "I001", "CPY", "RUF", "SIM", "UP"]
extend-ignore = [
"D203",
"D204",
Expand Down
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _init_config(self, container) -> bool:

self.render_pgb_config()
# Render the logrotate config
with open("templates/logrotate.j2", "r") as file:
with open("templates/logrotate.j2") as file:
template = Template(file.read())
container.push(
"/etc/logrotate.d/pgbouncer",
Expand Down Expand Up @@ -939,7 +939,7 @@ def render_pgb_config(self, reload_pgbouncer=False, restart=False) -> None:
min_pool_size = math.ceil(effective_db_connections / 4)
reserve_pool_size = math.ceil(effective_db_connections / 4)
service_ids = [service["id"] for service in self._services]
with open("templates/pgb_config.j2", "r") as file:
with open("templates/pgb_config.j2") as file:
template = Template(file.read())
databases = self._get_relation_config()
readonly_dbs = self._get_readonly_dbs(databases)
Expand Down
4 changes: 2 additions & 2 deletions src/relations/backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def initialise_auth_function(self, dbs: List[str]):
psycopg2.Error if self.postgres isn't usable.
"""
logger.info("initialising auth function")
with open("src/relations/sql/pgbouncer-install.sql", "r") as f:
with open("src/relations/sql/pgbouncer-install.sql") as f:
install_script = f.read()

for dbname in dbs:
Expand All @@ -437,7 +437,7 @@ def remove_auth_function(self, dbs: List[str]):
psycopg2.Error if self.postgres isn't usable.
"""
logger.info("removing auth function from backend relation")
with open("src/relations/sql/pgbouncer-uninstall.sql", "r") as f:
with open("src/relations/sql/pgbouncer-uninstall.sql") as f:
uninstall_script = f.read()
for dbname in dbs:
with self.postgres._connect_to_database(dbname) as conn, conn.cursor() as cursor:
Expand Down
2 changes: 1 addition & 1 deletion src/relations/peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
│ │ ╰────────────────────╯ ╰───────────────────╯ ╰───────────────────╯ │
-----------------------------------------------------------------------------------------------------------------------
""" # noqa: W505
"""

import logging
from typing import Optional, Set
Expand Down
2 changes: 1 addition & 1 deletion src/relations/pgbouncer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
│ │ │ <empty> │ │ <empty> │ │ │ <empty> │ │ <empty> │ │ <empty> │ │
│ │ ╰──────────────────╯ ╰─────────────────╯ │ ╰───────────────────╯ ╰────────────────────╯ ╰───────────────────╯ │
└──────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘
""" # noqa: W505
"""

import logging

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/helpers/ha_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
from typing import Dict, Tuple
from typing import Dict, Optional, Tuple

import psycopg2
import requests
Expand All @@ -16,7 +16,7 @@
from .helpers import CLIENT_APP_NAME


async def get_password(ops_test: OpsTest, app: str, down_unit: str = None) -> str:
async def get_password(ops_test: OpsTest, app: str, down_unit: Optional[str] = None) -> str:
"""Use the charm action to retrieve the password from provided application.
Returns:
Expand Down Expand Up @@ -57,7 +57,7 @@ async def check_writes(ops_test) -> int:
return total_expected_writes


async def are_writes_increasing(ops_test, down_unit: str = None) -> None:
async def are_writes_increasing(ops_test, down_unit: Optional[str] = None) -> None:
"""Verify new writes are continuing by counting the number of writes."""
writes, _ = await count_writes(ops_test, down_unit=down_unit)
for member, count in writes.items():
Expand All @@ -70,7 +70,7 @@ async def are_writes_increasing(ops_test, down_unit: str = None) -> None:


async def count_writes(
ops_test: OpsTest, down_unit: str = None
ops_test: OpsTest, down_unit: Optional[str] = None
) -> Tuple[Dict[str, int], Dict[str, int]]:
"""Count the number of writes in the database."""
app = "postgresql-k8s"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def get_endpoint_info(ops_test: OpsTest, unit_name: str, endpoint: str) ->
"--format=json",
)
relation_info = json.loads(get_databag[1])[unit_name]["relation-info"]
return list(filter(lambda x: x["endpoint"] == endpoint, relation_info))[0]["application-data"][
return next(filter(lambda x: x["endpoint"] == endpoint, relation_info))["application-data"][
"endpoints"
]

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/relations/pgbouncer_provider/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def get_application_relation_data(
application_name: str,
relation_name: str,
key: str,
relation_id: str = None,
relation_id: Optional[str] = None,
) -> Optional[str]:
"""Get relation data for an application.
Expand Down Expand Up @@ -130,7 +130,7 @@ async def is_external_connectivity_set(
ops_test: OpsTest,
application_name: str,
relation_name: str,
relation_id: str = None,
relation_id: Optional[str] = None,
) -> Optional[str]:
data = await get_application_relation_data(
ops_test,
Expand All @@ -149,9 +149,9 @@ async def build_connection_string(
application_name: str,
relation_name: str,
*,
relation_id: str = None,
relation_id: Optional[str] = None,
read_only_endpoint: bool = False,
database: str = None,
database: Optional[str] = None,
) -> str:
"""Build a PostgreSQL connection string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ async def test_read_only_endpoint_in_scaled_up_cluster(ops_test: OpsTest):
@pytest.mark.group(1)
async def test_each_relation_has_unique_credentials(ops_test: OpsTest):
"""Test that two different applications connect to the database with different credentials."""
all_app_names = [SECONDARY_CLIENT_APP_NAME] + APP_NAMES
all_app_names = [*SECONDARY_CLIENT_APP_NAME, APP_NAMES]

# Deploy secondary application.
await ops_test.model.deploy(
Expand Down Expand Up @@ -397,7 +397,7 @@ async def test_multiple_pgb_can_connect_to_one_backend(ops_test: OpsTest, pgb_ch
wait_for_relation_joined_between(ops_test, PG, pgb_secondary)

async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(apps=APP_NAMES + [pgb_secondary])
await ops_test.model.wait_for_idle(apps=[*APP_NAMES, pgb_secondary])

await ops_test.model.add_relation(
f"{SECONDARY_CLIENT_APP_NAME}:{SECOND_DATABASE_RELATION_NAME}", pgb_secondary
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/relations/test_backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_relation_broken(self, _delete_file, _render, _postgres):
"relations.backend_database.BackendDatabaseRequires.postgres", new_callable=PropertyMock
)
def test_initialise_auth_function(self, _postgres, _auth_user):
with open("src/relations/sql/pgbouncer-install.sql", "r") as f:
with open("src/relations/sql/pgbouncer-install.sql") as f:
install_script = f.read()
dbs = ["test-db"]

Expand Down

0 comments on commit 25c942a

Please sign in to comment.