Merge pull request 'Enable "all" ruff lint fixes' (#4978) from ruff into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4978
This commit is contained in:
Mic92
2025-08-26 11:26:47 +00:00
10 changed files with 72 additions and 60 deletions

View File

@@ -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:

View File

@@ -100,7 +100,6 @@ def profile(func: Callable) -> Callable:
"""
def wrapper(*args: Any, **kwargs: Any) -> Any:
global PROFS
profiler = PROFS[func]
try:

View File

@@ -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__)

View File

@@ -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.

View File

@@ -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

View File

@@ -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()

View File

@@ -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)

View File

@@ -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())
@@ -242,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),

View File

@@ -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()

View File

@@ -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"
]