From a7bce4cb194a423a0e62d8a880f381a9fd7823d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 20 Aug 2025 13:51:14 +0200 Subject: [PATCH 1/4] pyproject: enable all lints --- pyproject.toml | 100 +++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ebf4e7c9d..b26de2f2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,62 +10,80 @@ exclude = "clan_cli.nixpkgs" [tool.ruff] target-version = "py313" line-length = 88 -lint.select = [ - "A", - "ANN", - "ASYNC", - "B", - "C4", - "DTZ", - "E", - "EM", - "F", - "FA", - "I", - "ICN", - "ISC", - "LOG", - "N", - "PIE", - "PT", - "PTH", - "PYI", - "Q", - "RET", - "RSE", - "RUF", - "SIM", - "SLF", - "SLOT", - "T10", - "TID", - "TRY", - "U", - "W", - "YTT", -] +lint.select = [ "ALL" ] lint.ignore = [ "A003", # A005 Module `inspect` shadows a Python standard-library module # We might actually want to fix this. "A005", - "TRY301", - "TRY300", "ANN401", - "RUF100", - "TRY400", + "C901", + "COM812", + "D100", + "D101", + "D102", + "D103", + "D104", + "D105", + "D107", + "D200", + "D203", + "D213", + "D401", + "D415", "E402", "E501", "E731", + "ERA001", + "FBT001", + "FBT002", + "FIX", + "G001", + "G004", + "ISC001", + "PLR0911", + "PLR2004", "PT001", "PT023", "RET504", + "RUF100", + "S603", + "S607", "SIM102", "SIM108", "SIM112", - "ISC001", + "T201", + "TD", + "TRY400", + + # Maybe we can fix those + "D205", + "D400", + "PLR0912", + "PLR0913", + "PLR0915", + "TRY300", + "TRY301", + "FBT003", + "INP001", + # TODO: fix later + "PLC0415", ] [tool.ruff.lint.per-file-ignores] -"*_test.py" = ["SLF001"] -"test_*.py" = ["SLF001"] +"*_test.py" = [ + "SLF001", + "S101", + "S105" +] +"test_*.py" = [ + "SLF001", + "S101", + "S105" +] +"*/tests/*.py" = [ + "S101" +] +"*/fixtures/*.py" = [ + "S101" +] From 1dda60847ea1d404437a0fca8c61e4d374abf23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 20 Aug 2025 20:05:52 +0200 Subject: [PATCH 2/4] PLW0602: fix --- pkgs/clan-app/clan_app/api/file_gtk.py | 1 - pkgs/clan-cli/clan_cli/profiler.py | 1 - pkgs/clan-cli/clan_lib/async_run/__init__.py | 3 --- pkgs/clan-cli/clan_lib/cmd/__init__.py | 1 - 4 files changed, 6 deletions(-) diff --git a/pkgs/clan-app/clan_app/api/file_gtk.py b/pkgs/clan-app/clan_app/api/file_gtk.py index 2da3774da..a25a91c2c 100644 --- a/pkgs/clan-app/clan_app/api/file_gtk.py +++ b/pkgs/clan-app/clan_app/api/file_gtk.py @@ -91,7 +91,6 @@ def get_system_file( def gtk_open_file(file_request: FileRequest, op_key: str) -> bool: def returns(data: SuccessDataClass | ErrorDataClass) -> None: - global RESULT RESULT[op_key] = data def on_file_select(file_dialog: Gtk.FileDialog, task: Gio.Task) -> None: diff --git a/pkgs/clan-cli/clan_cli/profiler.py b/pkgs/clan-cli/clan_cli/profiler.py index 972f68e8f..802a5b103 100644 --- a/pkgs/clan-cli/clan_cli/profiler.py +++ b/pkgs/clan-cli/clan_cli/profiler.py @@ -100,7 +100,6 @@ def profile(func: Callable) -> Callable: """ def wrapper(*args: Any, **kwargs: Any) -> Any: - global PROFS profiler = PROFS[func] try: diff --git a/pkgs/clan-cli/clan_lib/async_run/__init__.py b/pkgs/clan-cli/clan_lib/async_run/__init__.py index 133d04d02..72d0ddeac 100644 --- a/pkgs/clan-cli/clan_lib/async_run/__init__.py +++ b/pkgs/clan-cli/clan_lib/async_run/__init__.py @@ -108,15 +108,12 @@ def set_should_cancel(should_cancel: Callable[[], bool]) -> None: def get_async_ctx() -> AsyncContext: """Retrieve the current AsyncContext, creating a new one if none exists.""" - global ASYNC_CTX_THREAD_LOCAL - if not hasattr(ASYNC_CTX_THREAD_LOCAL, "async_ctx"): ASYNC_CTX_THREAD_LOCAL.async_ctx = AsyncContext() return ASYNC_CTX_THREAD_LOCAL.async_ctx def set_async_ctx(ctx: AsyncContext) -> None: - global ASYNC_CTX_THREAD_LOCAL ASYNC_CTX_THREAD_LOCAL.async_ctx = ctx diff --git a/pkgs/clan-cli/clan_lib/cmd/__init__.py b/pkgs/clan-cli/clan_lib/cmd/__init__.py index 477063178..274430e3a 100644 --- a/pkgs/clan-cli/clan_lib/cmd/__init__.py +++ b/pkgs/clan-cli/clan_lib/cmd/__init__.py @@ -404,7 +404,6 @@ def run( if not is_async_cancelled(): process.wait() - global TIME_TABLE if TIME_TABLE: TIME_TABLE.add(shlex.join(cmd), timeit.default_timer() - start) From 63697ac4b1d43603352c069b5015b668b1157dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 26 Aug 2025 12:59:49 +0200 Subject: [PATCH 3/4] various fixes --- pkgs/clan-cli/clan_cli/templates/list.py | 3 ++- pkgs/clan-cli/clan_lib/api/serde.py | 6 +++--- pkgs/clan-cli/clan_lib/clan/get.py | 5 ++--- pkgs/clan-cli/clan_lib/machines/update.py | 6 ++++-- pkgs/clan-cli/clan_lib/tags/list.py | 4 +--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/templates/list.py b/pkgs/clan-cli/clan_cli/templates/list.py index 6338a15bd..56a25d3bc 100644 --- a/pkgs/clan-cli/clan_cli/templates/list.py +++ b/pkgs/clan-cli/clan_cli/templates/list.py @@ -1,12 +1,13 @@ from __future__ import annotations -import argparse import logging from typing import TYPE_CHECKING from clan_lib.templates import list_templates if TYPE_CHECKING: + import argparse + from clan_lib.nix_models.clan import TemplateClanType log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_lib/api/serde.py b/pkgs/clan-cli/clan_lib/api/serde.py index 85e1690fa..ffae996f0 100644 --- a/pkgs/clan-cli/clan_lib/api/serde.py +++ b/pkgs/clan-cli/clan_lib/api/serde.py @@ -277,9 +277,9 @@ def construct_value( inner_types = unwrap_union_type(t) # Construct the field value errors = [] - for t in inner_types: + for inner_type in inner_types: try: - return construct_value(t, field_value, loc) + return construct_value(inner_type, field_value, loc) except ClanError as exc: errors.append(exc) continue @@ -392,7 +392,7 @@ def construct_dataclass[T: Any]( field_values[field.name] = None else: field_values[field.name] = construct_value( - cast(type, field.type), field_value + cast("type", field.type), field_value ) # Check that all required field are present. diff --git a/pkgs/clan-cli/clan_lib/clan/get.py b/pkgs/clan-cli/clan_lib/clan/get.py index 5a929cfe5..ea304653e 100644 --- a/pkgs/clan-cli/clan_lib/clan/get.py +++ b/pkgs/clan-cli/clan_lib/clan/get.py @@ -38,8 +38,7 @@ def get_clan_details(flake: Flake) -> InventoryMeta: @API.register def get_clan_details_schema(flake: Flake) -> dict[str, FieldSchema]: - """ - Get attributes for each field of the clan. + """Get attributes for each field of the clan. This function checks which fields of the 'clan' resource are readonly and provides a reason if so. @@ -48,8 +47,8 @@ def get_clan_details_schema(flake: Flake) -> dict[str, FieldSchema]: Returns: dict[str, FieldSchema]: A map from field-names to { 'readonly' (bool) and 'reason' (str or None ) } - """ + """ inventory_store = InventoryStore(flake) write_info = inventory_store.get_writeability() diff --git a/pkgs/clan-cli/clan_lib/machines/update.py b/pkgs/clan-cli/clan_lib/machines/update.py index d0c84f91b..781c53b80 100644 --- a/pkgs/clan-cli/clan_lib/machines/update.py +++ b/pkgs/clan-cli/clan_lib/machines/update.py @@ -140,14 +140,16 @@ def run_machine_update( """ with ExitStack() as stack: _target_host: Host = cast( - Host, stack.enter_context(target_host.host_connection()) + "Host", stack.enter_context(target_host.host_connection()) ) _build_host: Host # If no build host is specified, use the target host as the build host. if build_host is None: _build_host = _target_host else: - _build_host = cast(Host, stack.enter_context(build_host.host_connection())) + _build_host = cast( + "Host", stack.enter_context(build_host.host_connection()) + ) # Some operations require root privileges on the target host. target_host_root = stack.enter_context(_target_host.become_root()) diff --git a/pkgs/clan-cli/clan_lib/tags/list.py b/pkgs/clan-cli/clan_lib/tags/list.py index 650ba2fc6..41caf6698 100644 --- a/pkgs/clan-cli/clan_lib/tags/list.py +++ b/pkgs/clan-cli/clan_lib/tags/list.py @@ -14,15 +14,13 @@ class TagList: @API.register def list_tags(flake: Flake) -> TagList: - """ - List all tags of a clan. + """List all tags of a clan. Returns: - 'options' - Existing Tags that can be added to machines - 'special' - Prefined Tags that are special and cannot be added to machines, they can be used in roles and refer to a fixed set of machines. """ - inventory_store = InventoryStore(flake=flake) inventory = inventory_store.read() From 6d2372be5602267346f72d8b8ffc3c9f1666969f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 26 Aug 2025 13:11:43 +0200 Subject: [PATCH 4/4] machines/update: fix incorrecct nixos-rebuild command --- pkgs/clan-cli/clan_lib/machines/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_lib/machines/update.py b/pkgs/clan-cli/clan_lib/machines/update.py index 781c53b80..c2dfb5503 100644 --- a/pkgs/clan-cli/clan_lib/machines/update.py +++ b/pkgs/clan-cli/clan_lib/machines/update.py @@ -244,7 +244,7 @@ def run_machine_update( "Mobile machine detected, applying workaround deployment method", ) ret = _build_host.run( - ["nixos--rebuild", "test", *nix_options] if is_mobile else switch_cmd, + ["nixos-rebuild", "test", *nix_options] if is_mobile else switch_cmd, RunOpts( log=Log.BOTH, msg_color=MsgColor(stderr=AnsiColor.DEFAULT),