From 26e3e3872cafb65be05b010351f4825b94af0023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 29 Nov 2023 12:38:00 +0100 Subject: [PATCH] enable more linting --- checks/lib/container-driver/pyproject.toml | 5 ++-- pkgs/clan-cli/clan_cli/config/__init__.py | 2 +- pkgs/clan-cli/clan_cli/flakes/add.py | 2 +- pkgs/clan-cli/clan_cli/flakes/history.py | 2 +- pkgs/clan-cli/clan_cli/machines/update.py | 33 +++++++++++----------- pkgs/clan-cli/clan_cli/nix.py | 28 +++++++++--------- pkgs/clan-cli/clan_cli/secrets/upload.py | 2 +- pkgs/clan-cli/clan_cli/ssh/__init__.py | 5 ++-- pkgs/clan-cli/clan_cli/ssh/cli.py | 5 ++-- pkgs/clan-cli/clan_cli/vms/run.py | 4 +-- pkgs/clan-cli/pyproject.toml | 6 ++-- pkgs/clan-cli/tests/helpers/cli.py | 2 +- pkgs/clan-cli/tests/test_config.py | 2 +- pkgs/clan-cli/tests/test_flake_api.py | 4 +-- pkgs/clan-vm-manager/pyproject.toml | 6 ++-- 15 files changed, 54 insertions(+), 54 deletions(-) diff --git a/checks/lib/container-driver/pyproject.toml b/checks/lib/container-driver/pyproject.toml index 088e026f..4479e341 100644 --- a/checks/lib/container-driver/pyproject.toml +++ b/checks/lib/container-driver/pyproject.toml @@ -16,13 +16,14 @@ find = {} test_driver = ["py.typed"] [tool.ruff] +target-version = "py311" line-length = 88 -select = ["E", "F", "I", "U", "N"] +select = ["E", "F", "I", "U", "N", "RUF"] ignore = ["E501"] [tool.mypy] -python_version = "3.10" +python_version = "3.11" warn_redundant_casts = true disallow_untyped_calls = true disallow_untyped_defs = true diff --git a/pkgs/clan-cli/clan_cli/config/__init__.py b/pkgs/clan-cli/clan_cli/config/__init__.py index e76c3d8a..d6d406b8 100644 --- a/pkgs/clan-cli/clan_cli/config/__init__.py +++ b/pkgs/clan-cli/clan_cli/config/__init__.py @@ -50,7 +50,7 @@ def merge(a: dict, b: dict, path: list[str] = []) -> dict: for key in b: if key in a: if isinstance(a[key], dict) and isinstance(b[key], dict): - merge(a[key], b[key], path + [str(key)]) + merge(a[key], b[key], [*path, str(key)]) elif isinstance(a[key], list) and isinstance(b[key], list): a[key].extend(b[key]) elif a[key] != b[key]: diff --git a/pkgs/clan-cli/clan_cli/flakes/add.py b/pkgs/clan-cli/clan_cli/flakes/add.py index 27be29a4..75f24a2b 100644 --- a/pkgs/clan-cli/clan_cli/flakes/add.py +++ b/pkgs/clan-cli/clan_cli/flakes/add.py @@ -14,7 +14,7 @@ async def add_flake(path: Path) -> Dict[str, CmdOut]: # TODO: Make this atomic lines: set = set() if user_history_file().exists(): - with open(user_history_file(), "r") as f: + with open(user_history_file()) as f: lines = set(f.readlines()) lines.add(str(path)) with open(user_history_file(), "w") as f: diff --git a/pkgs/clan-cli/clan_cli/flakes/history.py b/pkgs/clan-cli/clan_cli/flakes/history.py index 035cf3e8..2db34a9b 100644 --- a/pkgs/clan-cli/clan_cli/flakes/history.py +++ b/pkgs/clan-cli/clan_cli/flakes/history.py @@ -9,7 +9,7 @@ def list_history() -> list[Path]: if not user_history_file().exists(): return [] # read path lines from history file - with open(user_history_file(), "r") as f: + with open(user_history_file()) as f: lines = f.readlines() return [Path(line.strip()) for line in lines] diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index cd25eaff..a4fa25e0 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -49,23 +49,22 @@ def deploy_nixos(hosts: HostGroup, clan_dir: Path) -> None: if target_user: target_host = f"{target_user}@{target_host}" extra_args = h.meta.get("extra_args", []) - cmd = ( - ["nixos-rebuild", "switch"] - + extra_args - + [ - "--fast", - "--option", - "keep-going", - "true", - "--option", - "accept-flake-config", - "true", - "--build-host", - "", - "--flake", - f"{path}#{flake_attr}", - ] - ) + cmd = [ + "nixos-rebuild", + "switch", + *extra_args, + "--fast", + "--option", + "keep-going", + "true", + "--option", + "accept-flake-config", + "true", + "--build-host", + "", + "--flake", + f"{path}#{flake_attr}", + ] if target_host: cmd.extend(["--target-host", target_host]) ret = h.run(cmd, check=False) diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index 66beb412..b6ee3677 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -12,7 +12,7 @@ from .errors import ClanError @deal.raises(ClanError) def nix_command(flags: list[str]) -> list[str]: - return ["nix", "--extra-experimental-features", "nix-command flakes"] + flags + return ["nix", "--extra-experimental-features", "nix-command flakes", *flags] def nix_flake_show(flake_url: str | Path) -> list[str]: @@ -68,19 +68,17 @@ def nix_eval(flags: list[str]) -> list[str]: ) if os.environ.get("IN_NIX_SANDBOX"): with tempfile.TemporaryDirectory() as nix_store: - return ( - default_flags - + [ - "--override-input", - "nixpkgs", - str(nixpkgs_source()), - # --store is required to prevent this error: - # error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted - "--store", - nix_store, - ] - + flags - ) + return [ + *default_flags, + "--override-input", + "nixpkgs", + str(nixpkgs_source()), + # --store is required to prevent this error: + # error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted + "--store", + nix_store, + *flags, + ] return default_flags + flags @@ -96,7 +94,7 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: [ "shell", "--inputs-from", - f"{str(nixpkgs_flake())}", + f"{nixpkgs_flake()!s}", ] ) + wrapped_packages diff --git a/pkgs/clan-cli/clan_cli/secrets/upload.py b/pkgs/clan-cli/clan_cli/secrets/upload.py index 16f6702a..8250d3e1 100644 --- a/pkgs/clan-cli/clan_cli/secrets/upload.py +++ b/pkgs/clan-cli/clan_cli/secrets/upload.py @@ -28,7 +28,7 @@ def upload_secrets(machine: Machine) -> None: " ".join(["ssh"] + ssh_cmd[2:]), "-az", "--delete", - f"{str(tempdir)}/", + f"{tempdir!s}/", f"{host.user}@{host.host}:{machine.secrets_upload_directory}/", ], ), diff --git a/pkgs/clan-cli/clan_cli/ssh/__init__.py b/pkgs/clan-cli/clan_cli/ssh/__init__.py index 47c83b27..2b3d96b5 100644 --- a/pkgs/clan-cli/clan_cli/ssh/__init__.py +++ b/pkgs/clan-cli/clan_cli/ssh/__init__.py @@ -456,7 +456,8 @@ class Host: else: bash_cmd += cmd # FIXME we assume bash to be present here? Should be documented... - ssh_cmd = self.ssh_cmd(verbose_ssh=verbose_ssh) + [ + ssh_cmd = [ + *self.ssh_cmd(verbose_ssh=verbose_ssh), "--", f"{sudo}bash -c {quote(bash_cmd)} -- {' '.join(map(quote, bash_args))}", ] @@ -497,7 +498,7 @@ class Host: if verbose_ssh or self.verbose_ssh: ssh_opts.extend(["-v"]) - return ["ssh", ssh_target] + ssh_opts + return ["ssh", ssh_target, *ssh_opts] T = TypeVar("T") diff --git a/pkgs/clan-cli/clan_cli/ssh/cli.py b/pkgs/clan-cli/clan_cli/ssh/cli.py index da3d6bc5..6051c89c 100644 --- a/pkgs/clan-cli/clan_cli/ssh/cli.py +++ b/pkgs/clan-cli/clan_cli/ssh/cli.py @@ -21,7 +21,8 @@ def ssh( "-p", password, ] - _ssh_args = ssh_args + [ + _ssh_args = [ + *ssh_args, "ssh", "-o", "UserKnownHostsFile=/dev/null", @@ -29,7 +30,7 @@ def ssh( "StrictHostKeyChecking=no", f"{user}@{host}", ] - cmd = nix_shell(packages, ["torify"] + password_args + _ssh_args) + cmd = nix_shell(packages, ["torify", *password_args, *_ssh_args]) subprocess.run(cmd) diff --git a/pkgs/clan-cli/clan_cli/vms/run.py b/pkgs/clan-cli/clan_cli/vms/run.py index 76e49d1c..31756ea9 100644 --- a/pkgs/clan-cli/clan_cli/vms/run.py +++ b/pkgs/clan-cli/clan_cli/vms/run.py @@ -117,9 +117,9 @@ class BuildVmTask(BaseTask): cmd.run( nix_build( [ - f'{clan_dir}#clanInternals.machines."{system}"."{machine}".config.system.clan.vm.create' + f'{clan_dir}#clanInternals.machines."{system}"."{machine}".config.system.clan.vm.create', + *self.nix_options, ] - + self.nix_options ), name="buildvm", ) diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index a51b03fe..84f4f643 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -25,7 +25,7 @@ markers = ["impure", "with_core"] [tool.mypy] plugins = ["deal.mypy"] -python_version = "3.10" +python_version = "3.11" warn_redundant_casts = true disallow_untyped_calls = true disallow_untyped_defs = true @@ -53,7 +53,7 @@ module = "setuptools.*" ignore_missing_imports = true [tool.ruff] +target-version = "py311" line-length = 88 - -select = ["E", "F", "I", "N"] +select = ["E", "F", "I", "U", "N", "RUF"] ignore = ["E501", "E402"] diff --git a/pkgs/clan-cli/tests/helpers/cli.py b/pkgs/clan-cli/tests/helpers/cli.py index 44fc25d5..699325cd 100644 --- a/pkgs/clan-cli/tests/helpers/cli.py +++ b/pkgs/clan-cli/tests/helpers/cli.py @@ -11,7 +11,7 @@ log = logging.getLogger(__name__) class Cli: def run(self, args: list[str]) -> argparse.Namespace: parser = create_parser(prog="clan") - cmd = shlex.join(["clan"] + args) + cmd = shlex.join(["clan", *args]) log.debug(f"$ {cmd}") log.debug(f"Caller {get_caller()}") parsed = parser.parse_args(args) diff --git a/pkgs/clan-cli/tests/test_config.py b/pkgs/clan-cli/tests/test_config.py index 8a8c71bc..3b777a64 100644 --- a/pkgs/clan-cli/tests/test_config.py +++ b/pkgs/clan-cli/tests/test_config.py @@ -47,8 +47,8 @@ def test_set_some_option( example_options, "--settings-file", out_file.name, + *args, ] - + args ) json_out = json.loads(open(out_file.name).read()) assert json_out == expected diff --git a/pkgs/clan-cli/tests/test_flake_api.py b/pkgs/clan-cli/tests/test_flake_api.py index 0b1e7040..108d7b42 100644 --- a/pkgs/clan-cli/tests/test_flake_api.py +++ b/pkgs/clan-cli/tests/test_flake_api.py @@ -15,7 +15,7 @@ def test_flake_history_append( api: TestClient, test_flake: FlakeForTest, temporary_home: Path ) -> None: response = api.post( - f"/api/flake/history?flake_dir={str(test_flake.path)}", + f"/api/flake/history?flake_dir={test_flake.path!s}", json={}, ) assert response.status_code == 200, response.json() @@ -34,7 +34,7 @@ def test_flake_history_list( # add the test_flake response = api.post( - f"/api/flake/history?flake_dir={str(test_flake.path)}", + f"/api/flake/history?flake_dir={test_flake.path!s}", json={}, ) assert response.status_code == 200, response.text diff --git a/pkgs/clan-vm-manager/pyproject.toml b/pkgs/clan-vm-manager/pyproject.toml index 77276d4a..24795c5a 100644 --- a/pkgs/clan-vm-manager/pyproject.toml +++ b/pkgs/clan-vm-manager/pyproject.toml @@ -11,7 +11,7 @@ scripts = { clan-vm-manager = "clan_vm_manager:main" } clan_vm_manager = ["*.glade"] [tool.mypy] -python_version = "3.10" +python_version = "3.11" warn_redundant_casts = true disallow_untyped_calls = true disallow_untyped_defs = true @@ -22,7 +22,7 @@ module = "gi.*" ignore_missing_imports = true [tool.ruff] +target-version = "py311" line-length = 88 - -select = ["E", "F", "I", "N"] +select = ["E", "F", "I", "N", "RUF", "U"] ignore = ["E501", "E402", "N802"]