From 47467f6cce9e34f6c5b9fc30bae23cd43cfb0e75 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 6 Oct 2026 00:23:15 +0200 Subject: [PATCH] style: settle the formatter and ruff rewrites of this change set make autoformat reflowed a resource_filter call, a generator expression and five test files it touched along the way. The new architecture test also carried the two findings the first gate run stopped on: three RUF012, where a TestCase class attribute needs ClassVar, and two PERF401, where an append loop becomes list.extend over a generator. Co-Authored-By: Claude Opus 5 (1M context) --- plugins/lookup/gpu.py | 4 ++- .../files/python/infinito_docs/build_queue.py | 2 +- .../files/python/infinito_docs/builder.py | 4 +-- .../files/python/translate_gateway/router.py | 4 +-- .../update/docker/test_image_architectures.py | 29 ++++++++++--------- .../test_exec_requires_shell_module.py | 3 +- tests/unit/python/plugins/lookup/test_gpu.py | 20 +++++++++---- .../sys-svc-container/test_gpu_runtime.py | 4 +-- 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/plugins/lookup/gpu.py b/plugins/lookup/gpu.py index acddfba125..ef15fa69c9 100644 --- a/plugins/lookup/gpu.py +++ b/plugins/lookup/gpu.py @@ -73,5 +73,7 @@ class LookupModule(LookupBase): "applications", loader=self._loader, templar=templar ).run([], variables=variables)[0] - wanted = resource_filter(applications, application_id, "gpu", service_name, False) + wanted = resource_filter( + applications, application_id, "gpu", service_name, False + ) return [boolean(wanted, strict=False) and _device_present(variables)] diff --git a/roles/web-app-docs/files/python/infinito_docs/build_queue.py b/roles/web-app-docs/files/python/infinito_docs/build_queue.py index 5c1676b219..bddd449157 100644 --- a/roles/web-app-docs/files/python/infinito_docs/build_queue.py +++ b/roles/web-app-docs/files/python/infinito_docs/build_queue.py @@ -157,7 +157,7 @@ class Queue: self.build_language(version, code) else: self.build(version) - except Exception as exc: # noqa: BLE001 - a slot must not die silently + except Exception as exc: print(f"build {marker} crashed: {exc!r}", file=sys.stderr, flush=True) self._dequeue(marker) finally: diff --git a/roles/web-app-docs/files/python/infinito_docs/builder.py b/roles/web-app-docs/files/python/infinito_docs/builder.py index 4cd863a35a..29c6588444 100644 --- a/roles/web-app-docs/files/python/infinito_docs/builder.py +++ b/roles/web-app-docs/files/python/infinito_docs/builder.py @@ -182,9 +182,7 @@ class Builder: version: ``latest``, ``deployed`` or a release tag. ref: the commit or digest the version resolves to. """ - key = hashlib.sha256( - f"{ref}\0{self.tooling_ref()}".encode() - ).hexdigest()[:16] + key = hashlib.sha256(f"{ref}\0{self.tooling_ref()}".encode()).hexdigest()[:16] return self.prepared / f"{version}.{key}" @staticmethod diff --git a/roles/web-svc-translate/files/python/translate_gateway/router.py b/roles/web-svc-translate/files/python/translate_gateway/router.py index ad8338d90f..627511e496 100644 --- a/roles/web-svc-translate/files/python/translate_gateway/router.py +++ b/roles/web-svc-translate/files/python/translate_gateway/router.py @@ -283,9 +283,7 @@ class Router: lost = [term for term in protected if term not in answer] if text and Counter( character for character in answer if character in MARKUP_CHARACTERS - ) != Counter( - character for character in text if character in MARKUP_CHARACTERS - ): + ) != Counter(character for character in text if character in MARKUP_CHARACTERS): lost.append("the markup skeleton") return lost diff --git a/tests/external/update/docker/test_image_architectures.py b/tests/external/update/docker/test_image_architectures.py index 835ec13b7a..827fe7435c 100644 --- a/tests/external/update/docker/test_image_architectures.py +++ b/tests/external/update/docker/test_image_architectures.py @@ -48,6 +48,7 @@ from __future__ import annotations import collections import concurrent.futures import unittest +from typing import ClassVar from utils.annotations.message import warning from utils.docker.image.architectures import role_capability @@ -68,9 +69,9 @@ def _pull_image(ref) -> str: class ImageArchitectures(unittest.TestCase): """One registry sweep, shared by both rules.""" - probed: dict = {} - sources: collections.Counter = collections.Counter() - by_role: dict = {} + probed: ClassVar[dict] = {} + sources: ClassVar[collections.Counter] = collections.Counter() + by_role: ClassVar[dict] = {} @classmethod def setUpClass(cls) -> None: @@ -140,12 +141,12 @@ class ImageArchitectures(unittest.TestCase): capability, blame, _unread = self._capability(role) if capability is None: continue - for architecture in sorted(set(ARCHITECTURES) - capability): - offenders.append( - f"{role}: declares no `architectures`, so the matrix may " - f"place it on {architecture}, which " - f"{self._named(blame, architecture)} cannot run" - ) + offenders.extend( + f"{role}: declares no `architectures`, so the matrix may " + f"place it on {architecture}, which " + f"{self._named(blame, architecture)} cannot run" + for architecture in sorted(set(ARCHITECTURES) - capability) + ) self.assertEqual( [], offenders, @@ -163,11 +164,11 @@ class ImageArchitectures(unittest.TestCase): capability, blame, unread = self._capability(role) if capability is None: continue - for architecture in sorted(declared - capability): - offenders.append( - f"{role}: `architectures` claims {architecture}, which " - f"{self._named(blame, architecture)} cannot run" - ) + offenders.extend( + f"{role}: `architectures` claims {architecture}, which " + f"{self._named(blame, architecture)} cannot run" + for architecture in sorted(declared - capability) + ) stale = sorted(capability - declared) if stale and unread: warning( diff --git a/tests/lint/ansible/shell/container/test_exec_requires_shell_module.py b/tests/lint/ansible/shell/container/test_exec_requires_shell_module.py index 5471b40c78..1861684f7e 100644 --- a/tests/lint/ansible/shell/container/test_exec_requires_shell_module.py +++ b/tests/lint/ansible/shell/container/test_exec_requires_shell_module.py @@ -60,7 +60,8 @@ _JINJA = re.compile(r"\{\{[^}]+\}\}") _COMMAND_MODULES = frozenset({"command", "ansible.builtin.command"}) _EXEC_VERB = re.compile(r"\b(?:container|docker)\s+exec\b") _ADDRESS_VAR = re.compile( - r"^([A-Za-z_][A-Za-z0-9_]*)\s*:\s*\"?\{\{\s*lookup\('container_address'", re.M + r"^([A-Za-z_][A-Za-z0-9_]*)\s*:\s*\"?\{\{\s*lookup\('container_address'", + re.MULTILINE, ) diff --git a/tests/unit/python/plugins/lookup/test_gpu.py b/tests/unit/python/plugins/lookup/test_gpu.py index 8d123526c0..7132657c20 100644 --- a/tests/unit/python/plugins/lookup/test_gpu.py +++ b/tests/unit/python/plugins/lookup/test_gpu.py @@ -23,8 +23,12 @@ APPLICATIONS: ClassVar[dict] = { "web-app-truthy": {"services": {"truthy": {"gpu": "yes"}}}, } -PRESENT: ClassVar[dict] = {"sys_svc_container_nvidia_device": {"stat": {"exists": True}}} -ABSENT: ClassVar[dict] = {"sys_svc_container_nvidia_device": {"stat": {"exists": False}}} +PRESENT: ClassVar[dict] = { + "sys_svc_container_nvidia_device": {"stat": {"exists": True}} +} +ABSENT: ClassVar[dict] = { + "sys_svc_container_nvidia_device": {"stat": {"exists": False}} +} class _Templar: @@ -58,7 +62,9 @@ class TestGpuLookup(unittest.TestCase): def test_declared_without_a_device_is_false(self): """The case that selected a -cuda tag with no manifest for the platform.""" lm = _make_lookup(ABSENT) - self.assertEqual(_run(lm, ["web-svc-libretranslate", "libretranslate"]), [False]) + self.assertEqual( + _run(lm, ["web-svc-libretranslate", "libretranslate"]), [False] + ) def test_undeclared_with_a_device_is_false(self): lm = _make_lookup(PRESENT) @@ -67,11 +73,15 @@ class TestGpuLookup(unittest.TestCase): def test_missing_register_is_false(self): """Before sys-svc-container runs the register is absent, not falsy.""" lm = _make_lookup({}) - self.assertEqual(_run(lm, ["web-svc-libretranslate", "libretranslate"]), [False]) + self.assertEqual( + _run(lm, ["web-svc-libretranslate", "libretranslate"]), [False] + ) def test_non_mapping_register_is_false(self): lm = _make_lookup({"sys_svc_container_nvidia_device": "skipped"}) - self.assertEqual(_run(lm, ["web-svc-libretranslate", "libretranslate"]), [False]) + self.assertEqual( + _run(lm, ["web-svc-libretranslate", "libretranslate"]), [False] + ) def test_a_false_string_declaration_is_false(self): """Jinja's `| bool` reads "false" as False where bool() reads it as True. diff --git a/tests/unit/python/roles/sys-svc-container/test_gpu_runtime.py b/tests/unit/python/roles/sys-svc-container/test_gpu_runtime.py index 25ab2c9004..78342020a7 100644 --- a/tests/unit/python/roles/sys-svc-container/test_gpu_runtime.py +++ b/tests/unit/python/roles/sys-svc-container/test_gpu_runtime.py @@ -39,8 +39,8 @@ class TestGpuRuntimeRegistration(unittest.TestCase): undefined=StrictUndefined, autoescape=select_autoescape(), ) - env.filters["resource_filter"] = ( - lambda _apps, _id, _key, _svc, default, **_k: default + env.filters["resource_filter"] = lambda _apps, _id, _key, _svc, default, **_k: ( + default ) self.asked = []