nixos-rebuild-ng: enable unused arguments linter
This commit is contained in:
parent
749ded8826
commit
86665fc0a2
@ -366,9 +366,9 @@ def execute(argv: list[str]) -> None:
|
||||
|
||||
case Action.REPL:
|
||||
if flake:
|
||||
nix.repl_flake("toplevel", flake, flake_build_flags)
|
||||
nix.repl_flake(flake, flake_build_flags)
|
||||
else:
|
||||
nix.repl("system", build_attr, build_flags)
|
||||
nix.repl(build_attr, build_flags)
|
||||
|
||||
case _:
|
||||
assert_never(action)
|
||||
|
@ -154,7 +154,7 @@ class Flake:
|
||||
return cls(path, nixos_attr)
|
||||
|
||||
@classmethod
|
||||
def from_arg(cls, flake_arg: Any, target_host: Remote | None) -> Self | None:
|
||||
def from_arg(cls, flake_arg: Any, target_host: Remote | None) -> Self | None: # noqa: ANN401
|
||||
match flake_arg:
|
||||
case str(s):
|
||||
return cls.parse(s, target_host)
|
||||
|
@ -545,14 +545,14 @@ def list_generations(profile: Profile) -> list[GenerationJson]:
|
||||
)
|
||||
|
||||
|
||||
def repl(attr: str, build_attr: BuildAttr, nix_flags: Args | None = None) -> None:
|
||||
def repl(build_attr: BuildAttr, nix_flags: Args | None = None) -> None:
|
||||
run_args = ["nix", "repl", "--file", build_attr.path]
|
||||
if build_attr.attr:
|
||||
run_args.append(build_attr.attr)
|
||||
run_wrapper([*run_args, *dict_to_flags(nix_flags)])
|
||||
|
||||
|
||||
def repl_flake(attr: str, flake: Flake, flake_flags: Args | None = None) -> None:
|
||||
def repl_flake(flake: Flake, flake_flags: Args | None = None) -> None:
|
||||
expr = Template(
|
||||
files(__package__).joinpath(FLAKE_REPL_TEMPLATE).read_text()
|
||||
).substitute(
|
||||
|
@ -204,7 +204,6 @@ def _activate_system(
|
||||
path_to_config: Path,
|
||||
action: Action,
|
||||
args: argparse.Namespace,
|
||||
build_host: Remote | None,
|
||||
target_host: Remote | None,
|
||||
profile: Profile,
|
||||
flake: Flake | None,
|
||||
@ -309,7 +308,6 @@ def build_and_activate_system(
|
||||
path_to_config,
|
||||
action=action,
|
||||
args=args,
|
||||
build_host=build_host,
|
||||
target_host=target_host,
|
||||
profile=profile,
|
||||
flake=flake,
|
||||
|
@ -65,10 +65,21 @@ extend-select = [
|
||||
"ISC001",
|
||||
"ISC002",
|
||||
"ISC003",
|
||||
# unused arguments
|
||||
"ARG001",
|
||||
"ARG002",
|
||||
"ARG003",
|
||||
"ARG004",
|
||||
"ARG005",
|
||||
]
|
||||
ignore = [
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"tests/*" = [
|
||||
# allow unused arguments in tests (e.g., mocks)
|
||||
"ARG001",
|
||||
"ARG005",
|
||||
# allow Any type
|
||||
"ANN401"
|
||||
"ANN401"
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
|
@ -579,18 +579,18 @@ def test_list_generations(mock_get_generations: Mock, tmp_path: Path) -> None:
|
||||
|
||||
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
|
||||
def test_repl(mock_run: Mock) -> None:
|
||||
n.repl("attr", m.BuildAttr("<nixpkgs/nixos>", None), {"nix_flag": True})
|
||||
n.repl(m.BuildAttr("<nixpkgs/nixos>", None), {"nix_flag": True})
|
||||
mock_run.assert_called_with(
|
||||
["nix", "repl", "--file", "<nixpkgs/nixos>", "--nix-flag"]
|
||||
)
|
||||
|
||||
n.repl("attr", m.BuildAttr(Path("file.nix"), "myAttr"))
|
||||
n.repl(m.BuildAttr(Path("file.nix"), "myAttr"))
|
||||
mock_run.assert_called_with(["nix", "repl", "--file", Path("file.nix"), "myAttr"])
|
||||
|
||||
|
||||
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
|
||||
def test_repl_flake(mock_run: Mock) -> None:
|
||||
n.repl_flake("attr", m.Flake(Path("flake.nix"), "myAttr"), {"nix_flag": True})
|
||||
n.repl_flake(m.Flake(Path("flake.nix"), "myAttr"), {"nix_flag": True})
|
||||
# See nixos-rebuild-ng.tests.repl for a better test,
|
||||
# this is mostly for sanity check
|
||||
assert mock_run.call_count == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user