nixos-rebuild-ng: linter fixes

This commit is contained in:
Thiago Kenji Okada
2026-02-16 11:36:38 +00:00
parent dc0f2638f3
commit be9bcfc8f5
5 changed files with 25 additions and 20 deletions
@@ -201,7 +201,7 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
"--diff",
action="store_true",
help="prints out the diff between the current system "
"and the newly built one using nix store diff-closures"
"and the newly built one using nix store diff-closures",
)
main_parser.add_argument("action", choices=Action.values(), nargs="?")
@@ -1,7 +1,7 @@
import sys
import json
import logging
import os
import sys
import textwrap
import uuid
from concurrent.futures import ThreadPoolExecutor
@@ -540,12 +540,13 @@ def list_generations(profile: Profile) -> list[GenerationJson]:
reverse=True,
)
def diff_closures(current_config: Path, new_config: Path, target_host: Remote | None = None):
print(
f"<<< {current_config}\n"
f">>> {new_config}",
file=sys.stderr
)
def diff_closures(
current_config: Path,
new_config: Path,
target_host: Remote | None = None,
) -> None:
print(f"<<< {current_config}\n>>> {new_config}", file=sys.stderr)
run_wrapper(
[
"nix",
@@ -556,7 +557,7 @@ def diff_closures(current_config: Path, new_config: Path, target_host: Remote |
new_config,
],
remote=target_host,
stdout=sys.stderr
stdout=sys.stderr,
)
@@ -8,7 +8,7 @@ import subprocess
from collections.abc import Sequence
from dataclasses import dataclass
from ipaddress import AddressValueError, IPv6Address
from typing import Final, Self, TypedDict, Unpack
from typing import Final, Self, TextIO, TypedDict, Unpack
from . import tmpdir
@@ -85,8 +85,8 @@ class Remote:
# Not exhaustive, but we can always extend it later.
class RunKwargs(TypedDict, total=False):
capture_output: bool
stderr: int | None
stdout: int | None
stderr: int | TextIO | None
stdout: int | TextIO | None
def cleanup_ssh() -> None:
@@ -324,9 +324,15 @@ def build_and_activate_system(
current_config = Path("/run/current-system")
if args.diff:
if current_config.exists():
nix.diff_closures(current_config=current_config.readlink(), new_config=path_to_config, target_host=target_host)
nix.diff_closures(
current_config=current_config.readlink(),
new_config=path_to_config,
target_host=target_host,
)
else:
logger.warning(f"missing '{str(current_config)}', skipping configuration diff...")
logger.warning(
f"missing '{current_config!s}', skipping configuration diff..."
)
_activate_system(
path_to_config=path_to_config,
@@ -556,11 +556,9 @@ def test_list_generations(mock_get_generations: Mock, tmp_path: Path) -> None:
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
def test_diff_closures(mock_run: Mock) -> None:
assert n.diff_closures(
Path("/run/current-system"),
Path("/nix/var/nix/profiles/system"),
None
) == None
n.diff_closures(
Path("/run/current-system"), Path("/nix/var/nix/profiles/system"), None
)
mock_run.assert_called_with(
[
"nix",
@@ -572,7 +570,7 @@ def test_diff_closures(mock_run: Mock) -> None:
Path("/nix/var/nix/profiles/system"),
],
remote=None,
stdout=sys.stderr
stdout=sys.stderr,
)