Merge pull request 'ruff-3-arg-fixes' (#4934) from ruff-3-arg-fixes into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4934
This commit is contained in:
Mic92
2025-08-25 12:54:04 +00:00
52 changed files with 128 additions and 85 deletions

View File

@@ -19,6 +19,7 @@ class AppendOptionAction(argparse.Action):
values: str | Sequence[str] | None,
option_string: str | None = None,
) -> None:
del parser, option_string # Unused but required by argparse API
lst = getattr(namespace, self.dest)
lst.append("--option")
if not values or not hasattr(values, "__getitem__"):

View File

@@ -23,7 +23,6 @@ def test_clan_show(
def test_clan_show_no_flake(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
capture_output: CaptureOutput,
) -> None:
monkeypatch.chdir(tmp_path)

View File

@@ -38,9 +38,9 @@ def clan_dir(flake: str | None) -> str | None:
def complete_machines(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for machine names configured in the clan."""
machines: list[str] = []
@@ -72,9 +72,9 @@ def complete_machines(
def complete_services_for_machine(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for machine facts generation services."""
services: list[str] = []
@@ -117,9 +117,9 @@ def complete_services_for_machine(
def complete_backup_providers_for_machine(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for machine backup providers."""
providers: list[str] = []
@@ -161,9 +161,9 @@ def complete_backup_providers_for_machine(
def complete_state_services_for_machine(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for machine state providers."""
providers: list[str] = []
@@ -205,9 +205,9 @@ def complete_state_services_for_machine(
def complete_secrets(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for clan secrets"""
from clan_lib.flake.flake import Flake
@@ -228,9 +228,9 @@ def complete_secrets(
def complete_users(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for clan users"""
from pathlib import Path
@@ -251,9 +251,9 @@ def complete_users(
def complete_groups(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for clan groups"""
from pathlib import Path
@@ -275,9 +275,9 @@ def complete_groups(
def complete_templates_disko(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for disko templates"""
from clan_lib.templates import list_templates
@@ -299,9 +299,9 @@ def complete_templates_disko(
def complete_templates_clan(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for clan templates"""
from clan_lib.templates import list_templates
@@ -323,9 +323,9 @@ def complete_templates_clan(
def complete_vars_for_machine(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for variable names for a specific machine.
Only completes vars that already exist in the vars directory on disk.
@@ -367,9 +367,9 @@ def complete_vars_for_machine(
def complete_target_host(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for target_host for a specific machine"""
target_hosts: list[str] = []
@@ -409,9 +409,9 @@ def complete_target_host(
def complete_tags(
prefix: str,
_prefix: str,
parsed_args: argparse.Namespace,
**kwargs: Any,
**_kwargs: Any,
) -> Iterable[str]:
"""Provides completion functionality for tags inside the inventory"""
tags: list[str] = []

View File

@@ -151,7 +151,7 @@ def generate_service_facts(
return True
def prompt_func(service: str, text: str) -> str:
def prompt_func(_service: str, text: str) -> str:
print(f"{text}: ")
return read_multiline_input()

View File

@@ -12,6 +12,7 @@ class FactStore(FactStoreBase):
self.works_remotely = False
def set(self, service: str, name: str, value: bytes) -> Path | None:
del service # Unused but kept for API compatibility
if self.machine.flake.is_local:
fact_path = (
self.machine.flake.path
@@ -28,6 +29,7 @@ class FactStore(FactStoreBase):
raise ClanError(msg)
def exists(self, service: str, name: str) -> bool:
del service # Unused but kept for API compatibility
fact_path = (
self.machine.flake_dir / "machines" / self.machine.name / "facts" / name
)
@@ -35,6 +37,7 @@ class FactStore(FactStoreBase):
# get a single fact
def get(self, service: str, name: str) -> bytes:
del service # Unused but kept for API compatibility
fact_path = (
self.machine.flake_dir / "machines" / self.machine.name / "facts" / name
)

View File

@@ -34,6 +34,7 @@ class SecretStoreBase(ABC):
pass
def needs_upload(self, host: Host) -> bool:
del host # Unused but kept for API compatibility
return True
@abstractmethod

View File

@@ -22,6 +22,7 @@ class SecretStore(SecretStoreBase):
value: bytes,
groups: list[str],
) -> Path | None:
del service, groups # Unused but kept for API compatibility
subprocess.run(
nix_shell(
["pass"],
@@ -33,6 +34,7 @@ class SecretStore(SecretStoreBase):
return None # we manage the files outside of the git repo
def get(self, service: str, name: str) -> bytes:
del service # Unused but kept for API compatibility
return subprocess.run(
nix_shell(
["pass"],
@@ -43,6 +45,7 @@ class SecretStore(SecretStoreBase):
).stdout
def exists(self, service: str, name: str) -> bool:
del service # Unused but kept for API compatibility
password_store = os.environ.get(
"PASSWORD_STORE_DIR",
f"{os.environ['HOME']}/.password-store",

View File

@@ -43,6 +43,7 @@ class SecretStore(SecretStoreBase):
value: bytes,
groups: list[str],
) -> Path | None:
del service # Unused but kept for API compatibility
path = (
sops_secrets_folder(self.machine.flake_dir) / f"{self.machine.name}-{name}"
)
@@ -57,12 +58,14 @@ class SecretStore(SecretStoreBase):
return path
def get(self, service: str, name: str) -> bytes:
del service # Unused but kept for API compatibility
return decrypt_secret(
sops_secrets_folder(self.machine.flake_dir) / f"{self.machine.name}-{name}",
age_plugins=load_age_plugins(self.machine.flake),
).encode("utf-8")
def exists(self, service: str, name: str) -> bool:
del service # Unused but kept for API compatibility
return has_secret(
sops_secrets_folder(self.machine.flake_dir) / f"{self.machine.name}-{name}",
)

View File

@@ -21,6 +21,7 @@ class SecretStore(SecretStoreBase):
value: bytes,
groups: list[str],
) -> Path | None:
del groups # Unused but kept for API compatibility
secret_file = self.dir / service / name
secret_file.parent.mkdir(parents=True, exist_ok=True)
secret_file.write_bytes(value)

View File

@@ -39,6 +39,7 @@ class AppendDiskAction(argparse.Action):
values: str | Sequence[str] | None, # Updated type hint
option_string: str | None = None,
) -> None:
del parser, option_string # Unused but required by argparse API
# Ensure 'values' is a sequence of two elements
if not (
isinstance(values, Sequence)

View File

@@ -8,7 +8,7 @@ from clan_cli.tests.stdout import CaptureOutput
@pytest.mark.with_core
def test_flash_list_languages(
temporary_home: Path,
temporary_home: Path, # noqa: ARG001
capture_output: CaptureOutput,
) -> None:
with capture_output as output:
@@ -21,7 +21,7 @@ def test_flash_list_languages(
@pytest.mark.with_core
def test_flash_list_keymaps(
temporary_home: Path,
temporary_home: Path, # noqa: ARG001
capture_output: CaptureOutput,
) -> None:
with capture_output as output:

View File

@@ -9,7 +9,7 @@ from clan_cli.tests.stdout import CaptureOutput
def list_basic(
temporary_home: Path,
temporary_home: Path, # noqa: ARG001
test_flake_with_core: fixtures_flakes.FlakeForTest,
capture_output: CaptureOutput,
) -> None:
@@ -49,7 +49,7 @@ def list_basic(
indirect=True,
)
def list_with_tags_single_tag(
temporary_home: Path,
temporary_home: Path, # noqa: ARG001
test_flake_with_core: fixtures_flakes.FlakeForTest,
capture_output: CaptureOutput,
) -> None:
@@ -100,7 +100,7 @@ def list_with_tags_single_tag(
indirect=True,
)
def list_with_tags_multiple_tags_intersection(
temporary_home: Path,
temporary_home: Path, # noqa: ARG001
test_flake_with_core: fixtures_flakes.FlakeForTest,
capture_output: CaptureOutput,
) -> None:

View File

@@ -59,7 +59,7 @@ def generate_command(args: argparse.Namespace) -> None:
)
def show_command(args: argparse.Namespace) -> None:
def show_command(_args: argparse.Namespace) -> None:
keys = sops.maybe_get_admin_public_keys()
if not keys:
msg = "No public key found"

View File

@@ -27,6 +27,7 @@ class AppendSetAction(argparse.Action):
values: str | Sequence[str] | None,
option_string: str | None = None,
) -> None:
del parser, option_string # Unused but required by argparse API
lst = getattr(namespace, self.dest)
if not values or not hasattr(values, "__getitem__"):
msg = "values must be indexable"

View File

@@ -505,7 +505,7 @@ def writable_clan_core(
@pytest.fixture
def vm_test_flake(
clan_core: Path,
clan_core: Path, # noqa: ARG001
tmp_path: Path,
) -> Path:
"""Creates a test flake that imports the VM test nixOS modules from clan-core."""

View File

@@ -10,7 +10,6 @@ from clan_lib.templates.filesystem import copy_from_nixstore
@pytest.mark.with_core
def test_clan_core_templates(
test_flake_with_core: FlakeForTest,
monkeypatch: pytest.MonkeyPatch,
temporary_home: Path,
) -> None:
clan_dir = Flake(str(test_flake_with_core.path))

View File

@@ -67,8 +67,7 @@ def test_machine_subcommands(
@pytest.mark.with_core
def test_machines_update_with_tags(
test_flake_with_core: fixtures_flakes.FlakeForTest,
capture_output: CaptureOutput,
test_flake_with_core: fixtures_flakes.FlakeForTest, # noqa: ARG001
) -> None:
import argparse

View File

@@ -94,6 +94,7 @@ class StoreBase(ABC):
str | None: An error message describing issues found, or None if everything is healthy
"""
del machine, generators, file_name # Unused but kept for API compatibility
return None
def fix(
@@ -116,7 +117,7 @@ class StoreBase(ABC):
None
"""
return
del machine, generators, file_name # Unused but kept for API compatibility
def backend_collision_error(self, folder: Path) -> None:
msg = (

View File

@@ -41,6 +41,7 @@ class SecretStore(StoreBase):
return secret_file.read_bytes()
def populate_dir(self, machine: str, output_dir: Path, phases: list[str]) -> None:
del machine, phases # Unused but kept for API compatibility
if output_dir.exists():
shutil.rmtree(output_dir)
shutil.copytree(self.dir, output_dir)
@@ -53,6 +54,7 @@ class SecretStore(StoreBase):
return []
def delete_store(self, machine: str) -> list[Path]:
del machine # Unused but kept for API compatibility
if self.dir.exists():
shutil.rmtree(self.dir)
return []

View File

@@ -66,6 +66,7 @@ class SecretStore(StoreBase):
return [vars_dir]
def populate_dir(self, machine: str, output_dir: Path, phases: list[str]) -> None:
del phases # Unused but kept for API compatibility
vars_dir = self.get_dir(machine)
if output_dir.exists():
shutil.rmtree(output_dir)