Skip to content

Commit 134e1cb

Browse files
authored
style: fix linting errors (canonical#2229)
Fix linting errors from both the latest ruff and the latest pyright.
1 parent 00815ec commit 134e1cb

File tree

8 files changed

+26
-22
lines changed

8 files changed

+26
-22
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
- id: fix-byte-order-marker
1414
- id: mixed-line-ending
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: "v0.9.4"
16+
rev: "v0.11.0"
1717
hooks:
1818
# Run the linter
1919
- id: ruff

charmcraft/application/commands/store.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,9 @@ def run(self, parsed_args: argparse.Namespace) -> None:
24162416
updates = store.set_resource_revisions_architectures(
24172417
name=parsed_args.charm_name,
24182418
resource_name=parsed_args.resource_name,
2419-
updates={revision: parsed_args.arch for revision in parsed_args.revisions},
2419+
updates=dict.fromkeys(
2420+
parsed_args.revisions, cast("list[str]", parsed_args.arch)
2421+
),
24202422
)
24212423

24222424
fmt = parsed_args.format or cli.OutputFormat.TABLE

charmcraft/jujuignore.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,18 @@ def match(self, path: str, is_dir: bool) -> bool:
220220
# juju itself always includes these before adding the contents of .jujuignore
221221
# NOTE that this diverges from Juju ignore list, which also ignores "version",
222222
# because we need the version file to populate the store
223-
default_juju_ignore = """
224-
.git
225-
.svn
226-
.hg
227-
.bzr
228-
.tox
229-
230-
/build/
231-
/revision
232-
/venv
233-
234-
.jujuignore
235-
""".split("\n")
223+
default_juju_ignore = [
224+
"",
225+
".git",
226+
".svn",
227+
".hg",
228+
".bzr",
229+
".tox",
230+
"",
231+
"/build/",
232+
"/revision",
233+
"/venv",
234+
"",
235+
".jujuignore",
236+
"",
237+
]

charmcraft/utils/platform.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# noqa: A005 (This module shadows the stdlib platform module.)
21
# Copyright 2023 Canonical Ltd.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");

charmcraft/utils/yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _repr_str(dumper: yaml.SafeDumper, data: str) -> yaml.ScalarNode:
4545
return dumper.represent_scalar("tag:yaml.org,2002:str", data)
4646

4747

48-
def dump_yaml(data: Any) -> str: # noqa: ANN401: yaml.dump takes anything, so why can't we?
48+
def dump_yaml(data: Any) -> str: # noqa: ANN401 - yaml.dump takes anything, so why can't we?
4949
"""Dump a craft model to a YAML string."""
5050
yaml.add_representer(str, _repr_str, Dumper=yaml.SafeDumper)
5151
yaml.add_representer(

tests/unit/commands/test_lifecycle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import craft_cli
2323
import pytest
24-
import pytest_check
2524
from craft_cli.pytest_plugin import RecordingEmitter
2625

2726
from charmcraft import application, models, services, utils
@@ -135,6 +134,7 @@ def test_pack_update_charm_libs_empty(
135134
emitter: RecordingEmitter,
136135
service_factory: services.ServiceFactory,
137136
mock_store_anonymous_client: mock.Mock,
137+
check,
138138
):
139139
simple_charm.charm_libs = [models.CharmLib(lib="my_charm.my_lib", version="0.1")]
140140
store_lib = Library("lib_id", "my_lib", "my_charm", 0, 1, "Lib contents", "hash")
@@ -143,7 +143,7 @@ def test_pack_update_charm_libs_empty(
143143

144144
pack._update_charm_libs()
145145

146-
with pytest_check.check():
146+
with check():
147147
emitter.assert_debug(repr(store_lib))
148148

149149
path = fake_project_dir / utils.get_lib_path("my_charm", "my_lib", 0)

tests/unit/parts/plugins/test_python.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_get_package_install_commands(
5454
constraints: list[str],
5555
requirements: list[str],
5656
packages: list[str],
57+
check,
5758
):
5859
spec = {
5960
"plugin": "python",
@@ -73,9 +74,9 @@ def test_get_package_install_commands(
7374

7475
actual = python_plugin._get_package_install_commands()
7576

76-
with pytest_check.check():
77+
with check():
7778
assert actual[0].startswith("/python -m pip")
78-
with pytest_check.check():
79+
with check():
7980
assert actual[1].startswith("/python -m pip")
8081
split_install_command = shlex.split(actual[0])
8182
for constraints_file in constraints:

tests/unit/utils/test_charmlibs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def test_getlibinternals_missing_internals_field(
446446
):
447447
"""Some internals field is not present."""
448448
monkeypatch.chdir(tmp_path)
449-
kwargs = {arg: "" for arg in empty_args}
449+
kwargs = dict.fromkeys(empty_args, "")
450450
test_path = _create_lib(**kwargs)
451451
with pytest.raises(CraftError) as err:
452452
get_lib_internals(lib_path=test_path)

0 commit comments

Comments
 (0)