style: modernise typing and clean up lint findings

Repository-wide mechanical cleanup so `ruff check src tests` has a chance
of passing; no behavioural changes.

- Add `from __future__ import annotations` where PEP 604 unions are used.
  This has to come first: pyproject declares requires-python >= 3.9, where
  `X | None` is not evaluable at runtime unless annotations are stringified.
- Replace typing.List/Dict/Tuple/Set with the builtin generics and
  Optional[X] with X | None, then drop the imports that became unused.
  The four actions/*/__init__.py files needed this by hand because ruff
  leaves unused imports in __init__.py alone (possible re-exports).
- Strip shebangs from 72 importable modules. None of them are executable
  or invoked directly; the entry points are console_scripts and runpy.
- Flatten nested `with` blocks, collapse needless-bool returns, and apply
  the remaining mechanical ruff fixes (PIE810, FLY002, PERF102, FURB192,
  RUF059, I001).
- Pass check=False explicitly to the four subprocess.run() calls that
  inspect returncode themselves. That is the existing default.

Two rewrites are visible to mocks, so their tests move with them:
subprocess.run(stdout=PIPE, stderr=PIPE) became capture_output=True, and
open(path, "r", ...) lost the redundant mode.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-Birkenbach
2026-07-27 16:47:13 +02:00
parent 14b95d5639
commit b4e0594901
187 changed files with 591 additions and 856 deletions

View File

@@ -10,6 +10,7 @@ def run(cmd, *, cwd=None, env=None, shell=False) -> str:
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=False,
)
print("----- BEGIN COMMAND -----")

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
Integration tests for the `pkgmgr config` command.

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
Integration tests for the `pkgmgr make` command.

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
E2E test to inspect the Nix environment and build the pkgmgr flake
in *every* distro container.
@@ -36,6 +34,7 @@ def _run_cmd(cmd: list[str]) -> subprocess.CompletedProcess:
cmd,
text=True,
capture_output=True,
check=False,
)
print("[STDOUT]\n", proc.stdout)
print("[STDERR]\n", proc.stderr)

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
End-to-end tests for the `pkgmgr path` command.

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
End-to-end style integration tests for the `pkgmgr release` CLI command.
@@ -149,9 +147,12 @@ class TestIntegrationReleaseCommand(unittest.TestCase):
try:
sys.argv = ["pkgmgr", "release", "--help"]
# argparse will call sys.exit(), so we expect a SystemExit here.
with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf):
with self.assertRaises(SystemExit) as cm:
runpy.run_module("pkgmgr", run_name="__main__")
with (
contextlib.redirect_stdout(buf),
contextlib.redirect_stderr(buf),
self.assertRaises(SystemExit) as cm,
):
runpy.run_module("pkgmgr", run_name="__main__")
finally:
sys.argv = original_argv

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
Integration tests for the "tools" commands:

View File

@@ -15,10 +15,9 @@ from __future__ import annotations
import runpy
import sys
import unittest
from typing import List
def _run_main(argv: List[str]) -> None:
def _run_main(argv: list[str]) -> None:
"""
Helper to run main.py with the given argv.

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
End-to-end tests for the `pkgmgr version` command.
@@ -25,7 +23,6 @@ import os
import runpy
import sys
import unittest
from typing import List
from pkgmgr.core.config.load import load_config
@@ -54,7 +51,7 @@ def _load_pkgmgr_repo_dir() -> str:
directories = cfg.get("directories", {})
base_repos_dir = os.path.expanduser(directories.get("repositories", ""))
candidates: List[dict] = cfg.get("repositories", []) or []
candidates: list[dict] = cfg.get("repositories", []) or []
for repo in candidates:
repo_name = (repo.get("repository") or "").strip()
alias = (repo.get("alias") or "").strip()