Skip to content

chore: bump pre-commit versions, plus small fixes #1643

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

Merged
merged 8 commits into from
Mar 25, 2025
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -18,15 +18,15 @@ repos:
- id: detect-private-key
# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.5
rev: v0.11.2
hooks:
- id: ruff
args: [ --preview ]
- id: ruff-format
args: [ --preview ]
# Spellcheck the code.
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
* Change ops.main() so that you don't need to `type: ignore` it (#1345)
* Expand the secret ID out to the full URI when only given the ID (#1358)
* Add a JujuVersion property for Pebble log forwarding to Loki (#1370)
* Pre-emptively raise `InvalidStatusError` instead of waiting for Juju:
* Preemptively raise `InvalidStatusError` instead of waiting for Juju:
* Make it an error to call `CollectStatusEvent.add_status` with error or unknown (#1386)
* Document and validate settable status values in `_ModelBackend.set_status` (#1354)

Expand Down
7 changes: 3 additions & 4 deletions ops/_private/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ExecResult:
stderr: Union[str, bytes] = b''


ExecHandler = Callable[[ExecArgs], Union[None, ExecResult]]
ExecHandler = Callable[[ExecArgs], Union[ExecResult, None]]


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -1796,8 +1796,7 @@ def revoke_secret(self, secret_id: str, observer: AppUnitOrName):
# Model secrets:
if secret.owner_name in [self.model.app.name, self.model.unit.name]:
raise RuntimeError(
f'Secret {secret_id!r} owned by the charm under test, "'
f"can't call revoke_secret"
f"Secret {secret_id!r} owned by the charm under test, can't call revoke_secret"
)

relation_id = self._secret_relation_id_to(secret)
Expand Down Expand Up @@ -2119,7 +2118,7 @@ def run_action(
f'given {{"{key}":{params[key]!r}}}'
)
action_under_test = _RunningAction(action_name, ActionOutput([], {}), params)
handler = getattr(self.charm.on, f"{action_name.replace('-', '_')}_action")
handler = getattr(self.charm.on, f'{action_name.replace("-", "_")}_action')
self._backend._running_action = action_under_test
self._action_id_counter += 1
handler.emit(str(self._action_id_counter))
Expand Down
6 changes: 3 additions & 3 deletions ops/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,9 @@ class SomeObject:

method_name = observer.__name__

assert isinstance(observer.__self__, Object), (
"can't register observers " "that aren't `Object`s"
)
assert isinstance(
observer.__self__, Object
), "can't register observers that aren't `Object`s"
observer_obj = observer.__self__

# Validate that the method has an acceptable call signature.
Expand Down
8 changes: 4 additions & 4 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ def __repr__(self):
fields.append(f'id={self._id!r}')
if self._label is not None:
fields.append(f'label={self._label!r}')
return f"<Secret {' '.join(fields)}>"
return f'<Secret {" ".join(fields)}>'

@staticmethod
def _canonicalize_id(id: str, model_uuid: Optional[str]) -> str:
Expand Down Expand Up @@ -2224,7 +2224,7 @@ def request(self, storage_name: str, count: int = 1):
"""
if storage_name not in self._storage_map:
raise ModelError(
f'cannot add storage {storage_name!r}:' ' it is not present in the charm metadata'
f'cannot add storage {storage_name!r}: it is not present in the charm metadata'
)
self._backend.storage_add(storage_name, count)

Expand Down Expand Up @@ -3913,12 +3913,12 @@ def validate_metric_label(cls, label_name: str):
def format_metric_value(cls, value: Union[int, float]):
if not isinstance(value, (int, float)):
raise ModelError(
f'invalid metric value {value!r} provided:' ' must be a positive finite float'
f'invalid metric value {value!r} provided: must be a positive finite float'
)

if math.isnan(value) or math.isinf(value) or value < 0:
raise ModelError(
f'invalid metric value {value!r} provided:' ' must be a positive finite float'
f'invalid metric value {value!r} provided: must be a positive finite float'
)
return str(value)

Expand Down
16 changes: 3 additions & 13 deletions ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,7 @@ def from_dict(cls, d: _ProgressDict) -> TaskProgress:
)

def __repr__(self):
return (
'TaskProgress('
f'label={self.label!r}, '
f'done={self.done!r}, '
f'total={self.total!r})'
)
return f'TaskProgress(label={self.label!r}, done={self.done!r}, total={self.total!r})'


class TaskID(str):
Expand Down Expand Up @@ -1088,12 +1083,7 @@ def from_dict(cls, d: _ServiceInfoDict) -> ServiceInfo:
)

def __repr__(self):
return (
'ServiceInfo('
f'name={self.name!r}, '
f'startup={self.startup}, '
f'current={self.current})'
)
return f'ServiceInfo(name={self.name!r}, startup={self.startup}, current={self.current})'


class Check:
Expand Down Expand Up @@ -2604,7 +2594,7 @@ def _encode_multipart(
source_io: _AnyStrFileLikeIO = source # type: ignore
boundary = binascii.hexlify(os.urandom(16))
path_escaped = path.replace('"', '\\"').encode('utf-8')
content_type = f"multipart/form-data; boundary=\"{boundary.decode('utf-8')}\""
content_type = f'multipart/form-data; boundary="{boundary.decode("utf-8")}"'

def generator() -> Generator[bytes, None, None]:
yield b''.join([
Expand Down
3 changes: 2 additions & 1 deletion test/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,8 @@ def test_breakpoint_good_names(self, request: pytest.FixtureRequest, name: str):
'-',
'...foo',
'foo.bar',
'bar--' 'FOO',
'bar--',
'FOO',
'FooBar',
'foo bar',
'foo_bar',
Expand Down
4 changes: 2 additions & 2 deletions test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def _on_cluster_relation_changed(self, event: ops.EventBase):
harness.set_leader(False)
harness.update_relation_data(rel_id, 'test-app', {'k': 'v3'})
assert backend.relation_get(rel_id, 'test-app', is_app=True) == {'k': 'v3'}
assert len(harness.charm.observed_events), 1
assert len(harness.charm.observed_events) == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch!

assert isinstance(harness.charm.observed_events[0], ops.RelationEvent)

def test_remove_relation(self, request: pytest.FixtureRequest):
Expand Down Expand Up @@ -5192,7 +5192,7 @@ def test_list_files_not_found_raises(
client.list_files('/not/existing/file/')
assert excinfo.value.code == 404
assert excinfo.value.status == 'Not Found'
assert excinfo.value.message == 'stat /not/existing/file/: no ' 'such file or directory'
assert excinfo.value.message == 'stat /not/existing/file/: no such file or directory'

def test_list_directory_object_itself(
self,
Expand Down
1 change: 0 additions & 1 deletion testing/src/scenario/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down
1 change: 0 additions & 1 deletion testing/src/scenario/_consistency_checker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down
1 change: 0 additions & 1 deletion testing/src/scenario/_ops_main_mock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down
1 change: 0 additions & 1 deletion testing/src/scenario/_runtime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down
1 change: 0 additions & 1 deletion testing/src/scenario/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down
1 change: 0 additions & 1 deletion testing/src/scenario/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down
1 change: 0 additions & 1 deletion testing/src/scenario/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down
4 changes: 1 addition & 3 deletions testing/src/scenario/mocking.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down Expand Up @@ -428,8 +427,7 @@ def _check_can_manage_secret(
)
if secret.owner == "app" and not self.is_leader():
understandable_error = SecretNotFoundError(
f"App-owned secret {secret.id!r} can only be "
f"managed by the leader.",
f"App-owned secret {secret.id!r} can only be managed by the leader.",
)
# charm-facing side: respect ops error
raise ModelError("ERROR permission denied") from understandable_error
Expand Down
3 changes: 1 addition & 2 deletions testing/src/scenario/state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down Expand Up @@ -1925,7 +1924,7 @@ class _Event: # type: ignore

path: str
"""The name of the event.

For example: ``start``, ``config_changed``, ``my_relation_joined``, or
``custom.MyConsumer.lib_changed``.

Expand Down
1 change: 0 additions & 1 deletion testing/tests/test_e2e/test_resource.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

Expand Down