Skip to content
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

fix linting issues for ruff 0.6 #815

Merged
merged 2 commits into from
Aug 19, 2024
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
14 changes: 7 additions & 7 deletions craft_parts/plugins/maven_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import os
import re
import xml.etree.ElementTree as ET
from pathlib import Path
from typing import Literal, cast
from urllib.parse import urlparse
from xml.etree import ElementTree

from overrides import override

Expand Down Expand Up @@ -139,7 +139,7 @@ def _create_settings(settings_path: Path) -> None:

:param settings_path: the location the settings file will be created.
"""
settings = ElementTree.Element(
settings = ET.Element(
"settings",
attrib={
"xmlns": "http://maven.apache.org/SETTINGS/1.0.0",
Expand All @@ -150,18 +150,18 @@ def _create_settings(settings_path: Path) -> None:
),
},
)
element = ElementTree.Element("interactiveMode")
element = ET.Element("interactiveMode")
element.text = "false"
settings.append(element)
proxies = ElementTree.Element("proxies")
proxies = ET.Element("proxies")

for protocol in ("http", "https"):
env_name = f"{protocol}_proxy"
if env_name not in os.environ:
continue

proxy_url = urlparse(os.environ[env_name])
proxy = ElementTree.Element("proxy")
proxy = ET.Element("proxy")
proxy_tags = [
("id", env_name),
("active", "true"),
Expand All @@ -176,14 +176,14 @@ def _create_settings(settings_path: Path) -> None:
proxy_tags.append(("nonProxyHosts", _get_no_proxy_string()))

for tag, text in proxy_tags:
element = ElementTree.Element(tag)
element = ET.Element(tag)
element.text = text
proxy.append(element)

proxies.append(proxy)

settings.append(proxies)
tree = ElementTree.ElementTree(settings)
tree = ET.ElementTree(settings)
os.makedirs(os.path.dirname(settings_path), exist_ok=True)

with settings_path.open("w") as file:
Expand Down
24 changes: 12 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def pytest_configure(config):
)


@pytest.fixture()
@pytest.fixture
def new_dir(monkeypatch, tmpdir):
"""Change to a new temporary directory."""
monkeypatch.chdir(tmpdir)
return tmpdir


@pytest.fixture()
@pytest.fixture
def tmp_homedir_path():
"""A non-hidden temporary directory in the user's home directory.

Expand All @@ -58,7 +58,7 @@ def tmp_homedir_path():
yield pathlib.Path(tmp_dir)


@pytest.fixture()
@pytest.fixture
def new_homedir_path(monkeypatch, tmp_homedir_path):
"""Change to a new temporary directory in the user's home directory.

Expand All @@ -68,21 +68,21 @@ def new_homedir_path(monkeypatch, tmp_homedir_path):
return tmp_homedir_path


@pytest.fixture()
@pytest.fixture
def mock_chdir(monkeypatch):
mock_fn = mock.Mock(spec=os.chdir)
monkeypatch.setattr(os, "chdir", mock_fn)
return mock_fn


@pytest.fixture()
@pytest.fixture
def mock_chroot(monkeypatch):
mock_fn = mock.Mock(spec=os.chroot)
monkeypatch.setattr(os, "chroot", mock_fn)
return mock_fn


@pytest.fixture()
@pytest.fixture
def enable_overlay_feature():
assert Features().enable_overlay is False
Features.reset()
Expand All @@ -93,7 +93,7 @@ def enable_overlay_feature():
Features.reset()


@pytest.fixture()
@pytest.fixture
def enable_partitions_feature():
assert Features().enable_partitions is False
Features.reset()
Expand All @@ -104,14 +104,14 @@ def enable_partitions_feature():
Features.reset()


@pytest.fixture()
@pytest.fixture
def partitions():
if Features().enable_partitions:
return ["default", "mypart", "yourpart"]
return None


@pytest.fixture()
@pytest.fixture
def enable_all_features():
assert Features().enable_overlay is False
assert Features().enable_partitions is False
Expand Down Expand Up @@ -195,13 +195,13 @@ def fake_snapd():
socket_path_patcher.stop()


@pytest.fixture()
@pytest.fixture
def fake_snap_command(mocker):
"""Mock the snap command."""
return FakeSnapCommand(mocker)


@pytest.fixture()
@pytest.fixture
def dependency_fixture(new_dir):
"""Fixture factory for dependencies."""

Expand Down Expand Up @@ -244,7 +244,7 @@ class ChmodCall(NamedTuple):
kwargs: dict[str, Any]


@pytest.fixture()
@pytest.fixture
def mock_chown(mocker) -> dict[str, ChmodCall]:
"""Mock os.chown() and keep a record of calls to it.

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/executor/test_collisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class TestCollisions:
"""Test collision scenarios."""

@pytest.fixture()
@pytest.fixture
def stub_parts_yaml(self) -> dict[str, Any]:
"""Return a part dictionary containing 2 parts."""
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestCollisions(test_collisions.TestCollisions):
class TestCollisionsInPartitions:
"""Test collision scenarios in partition stage dirs."""

@pytest.fixture()
@pytest.fixture
def stub_parts_yaml(self) -> dict[str, Any]:
"""Return a part dictionary containing 2 parts."""
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def setup_method_fixture(self, new_dir, partitions):
partitions=partitions,
)

@pytest.fixture()
@pytest.fixture
def foo_files(self):
"""Return a dictionary of steps and the files created by that step for foo."""
return {
Expand Down Expand Up @@ -130,7 +130,7 @@ def foo_files(self):
],
}

@pytest.fixture()
@pytest.fixture
def bar_files(self):
"""Return a dictionary of steps and the files created by that step for bar."""
return {
Expand All @@ -156,7 +156,7 @@ def bar_files(self):
],
}

@pytest.fixture()
@pytest.fixture
def state_files(self):
return ["build", "prime", "pull", "stage"]

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/lifecycle/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def setup_method_fixture(self, new_dir, partitions):

# pylint: enable=attribute-defined-outside-init

@pytest.fixture()
@pytest.fixture
def foo_files(self):
return [
Path("parts/foo/src/foo.txt"),
Expand All @@ -271,7 +271,7 @@ def foo_files(self):
Path("prime/foo.txt"),
]

@pytest.fixture()
@pytest.fixture
def bar_files(self):
return [
Path("parts/bar/src/bar.txt"),
Expand All @@ -280,7 +280,7 @@ def bar_files(self):
Path("prime/bar.txt"),
]

@pytest.fixture()
@pytest.fixture
def state_files(self):
return ["build", "prime", "pull", "stage"]

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/lifecycle/test_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setup_feature(enable_overlay_feature):
return


@pytest.fixture()
@pytest.fixture
def fake_call(mocker):
return mocker.patch("subprocess.check_call")

Expand All @@ -48,7 +48,7 @@ def mock_overlay_support_prerequisites(mocker):


class TestOverlayLayerOrder:
@pytest.fixture()
@pytest.fixture
def lifecycle(self, new_dir):
parts_yaml = textwrap.dedent(
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/lifecycle/test_stage_snaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
_LOCAL_DIR = Path(__file__).parent


@pytest.fixture()
@pytest.fixture
def foo_install_dir(new_dir):
return Path(new_dir, "parts", "foo", "install")

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/plugins/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from craft_parts import Action, Step


@pytest.fixture()
@pytest.fixture
def install_dir():
"""Installation directory for the standard dump plugin."""
return Path("parts", "foo", "install")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/plugins/test_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from craft_parts import LifecycleManager, Step


@pytest.fixture()
@pytest.fixture
def meson():
subprocess.run(["pip", "install", "meson"], check=True)
yield
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/plugins/test_validate_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from craft_parts import Step, errors, plugins


@pytest.fixture()
@pytest.fixture
def mytool(new_dir):
tool = Path(new_dir, "mock_bin", "mytool")
tool.parent.mkdir(exist_ok=True)
Expand All @@ -34,7 +34,7 @@ def mytool(new_dir):
return tool


@pytest.fixture()
@pytest.fixture
def mytool_not_ok(new_dir):
tool = Path(new_dir, "mock_bin", "mytool")
tool.parent.mkdir(exist_ok=True)
Expand All @@ -43,7 +43,7 @@ def mytool_not_ok(new_dir):
return tool


@pytest.fixture()
@pytest.fixture
def mytool_error(new_dir):
tool = Path(new_dir, "mock_bin", "mytool")
tool.parent.mkdir(exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/sequencer/test_sequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
)


@pytest.fixture()
@pytest.fixture
def pull_state(new_dir):
# build current state
Path(new_dir / "parts/foo/state").mkdir(parents=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/sequencer/test_sequencer_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def setup_feature(enable_overlay_feature):
)


@pytest.fixture()
@pytest.fixture
def pull_state(new_dir):
# build current state
Path(new_dir / "parts/foo/state").mkdir(parents=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/sources/test_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from craft_parts.steps import Step


@pytest.fixture()
@pytest.fixture
def sample_deb(tmp_path: Path) -> Path:
"""
Create a basic .deb file and return its path.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/sources/test_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from craft_parts.steps import Step


@pytest.fixture()
@pytest.fixture
def sample_rpm(tmp_path: Path) -> Path:
"""
Create a basic .rpm file and return its path.
Expand Down
Loading
Loading