Commit be9bcfc8 authored by Thiago Kenji Okada's avatar Thiago Kenji Okada
Browse files

nixos-rebuild-ng: linter fixes

parent dc0f2638
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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="?")

+9 −8
Original line number Diff line number Diff line
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,
    )


+3 −3
Original line number Diff line number Diff line
@@ -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:
+8 −2
Original line number Diff line number Diff line
@@ -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,
+4 −6
Original line number Diff line number Diff line
@@ -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,
    )