From c23f394eb863a24ec5ecfe823d43f1188ec89de2 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sun, 28 Jun 2026 01:42:15 -0700 Subject: [PATCH] fix: satisfy ruff encoding + windows-footgun lints for cgroup reaper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - read_text(encoding='utf-8') (PLW1514) - # windows-footgun: ok on signal.SIGKILL — module is Linux-only (reads /proc, /sys/fs/cgroup; runs from a systemd unit) - test lambda accepts the new encoding kwarg --- gateway/cgroup_cleanup.py | 6 +++--- tests/gateway/test_cgroup_cleanup.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gateway/cgroup_cleanup.py b/gateway/cgroup_cleanup.py index 9a6225784d1..a364294b909 100644 --- a/gateway/cgroup_cleanup.py +++ b/gateway/cgroup_cleanup.py @@ -24,7 +24,7 @@ from pathlib import Path def _own_cgroup_path() -> str | None: """Return the cgroup v2 path for the calling process, or None.""" try: - text = Path("/proc/self/cgroup").read_text() + text = Path("/proc/self/cgroup").read_text(encoding="utf-8") except OSError: return None match = re.search(r"^0::(.+)$", text, re.MULTILINE) @@ -36,7 +36,7 @@ def _own_cgroup_path() -> str | None: def _read_cgroup_pids(cgroup_path: str) -> list[int]: procs_file = Path(f"/sys/fs/cgroup{cgroup_path}/cgroup.procs") try: - raw = procs_file.read_text() + raw = procs_file.read_text(encoding="utf-8") except OSError: return [] pids: list[int] = [] @@ -63,7 +63,7 @@ def reap_cgroup(cgroup_path: str | None = None) -> int: if pid == own: continue try: - os.kill(pid, signal.SIGKILL) + os.kill(pid, signal.SIGKILL) # windows-footgun: ok — Linux-only (reads /proc, /sys/fs/cgroup; runs from a systemd unit) killed += 1 except ProcessLookupError: continue diff --git a/tests/gateway/test_cgroup_cleanup.py b/tests/gateway/test_cgroup_cleanup.py index e0395881311..5e15ed9a9ae 100644 --- a/tests/gateway/test_cgroup_cleanup.py +++ b/tests/gateway/test_cgroup_cleanup.py @@ -27,7 +27,7 @@ class TestOwnCgroupPath: def _raise(_path): raise FileNotFoundError - monkeypatch.setattr(cgroup_cleanup.Path, "read_text", lambda self: _raise(self)) + monkeypatch.setattr(cgroup_cleanup.Path, "read_text", lambda self, *a, **k: _raise(self)) assert cgroup_cleanup._own_cgroup_path() is None