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:
|
case Action.REPL:
|
||||||
if flake:
|
if flake:
|
||||||
nix.repl_flake("toplevel", flake, flake_build_flags)
|
nix.repl_flake(flake, flake_build_flags)
|
||||||
else:
|
else:
|
||||||
nix.repl("system", build_attr, build_flags)
|
nix.repl(build_attr, build_flags)
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
assert_never(action)
|
assert_never(action)
|
||||||
|
@ -154,7 +154,7 @@ class Flake:
|
|||||||
return cls(path, nixos_attr)
|
return cls(path, nixos_attr)
|
||||||
|
|
||||||
@classmethod
|
@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:
|
match flake_arg:
|
||||||
case str(s):
|
case str(s):
|
||||||
return cls.parse(s, target_host)
|
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]
|
run_args = ["nix", "repl", "--file", build_attr.path]
|
||||||
if build_attr.attr:
|
if build_attr.attr:
|
||||||
run_args.append(build_attr.attr)
|
run_args.append(build_attr.attr)
|
||||||
run_wrapper([*run_args, *dict_to_flags(nix_flags)])
|
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(
|
expr = Template(
|
||||||
files(__package__).joinpath(FLAKE_REPL_TEMPLATE).read_text()
|
files(__package__).joinpath(FLAKE_REPL_TEMPLATE).read_text()
|
||||||
).substitute(
|
).substitute(
|
||||||
|
@ -204,7 +204,6 @@ def _activate_system(
|
|||||||
path_to_config: Path,
|
path_to_config: Path,
|
||||||
action: Action,
|
action: Action,
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
build_host: Remote | None,
|
|
||||||
target_host: Remote | None,
|
target_host: Remote | None,
|
||||||
profile: Profile,
|
profile: Profile,
|
||||||
flake: Flake | None,
|
flake: Flake | None,
|
||||||
@ -309,7 +308,6 @@ def build_and_activate_system(
|
|||||||
path_to_config,
|
path_to_config,
|
||||||
action=action,
|
action=action,
|
||||||
args=args,
|
args=args,
|
||||||
build_host=build_host,
|
|
||||||
target_host=target_host,
|
target_host=target_host,
|
||||||
profile=profile,
|
profile=profile,
|
||||||
flake=flake,
|
flake=flake,
|
||||||
|
@ -65,8 +65,19 @@ extend-select = [
|
|||||||
"ISC001",
|
"ISC001",
|
||||||
"ISC002",
|
"ISC002",
|
||||||
"ISC003",
|
"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
|
# allow Any type
|
||||||
"ANN401"
|
"ANN401"
|
||||||
]
|
]
|
||||||
|
@ -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)
|
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
|
||||||
def test_repl(mock_run: Mock) -> None:
|
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(
|
mock_run.assert_called_with(
|
||||||
["nix", "repl", "--file", "<nixpkgs/nixos>", "--nix-flag"]
|
["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"])
|
mock_run.assert_called_with(["nix", "repl", "--file", Path("file.nix"), "myAttr"])
|
||||||
|
|
||||||
|
|
||||||
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
|
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
|
||||||
def test_repl_flake(mock_run: Mock) -> None:
|
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,
|
# See nixos-rebuild-ng.tests.repl for a better test,
|
||||||
# this is mostly for sanity check
|
# this is mostly for sanity check
|
||||||
assert mock_run.call_count == 1
|
assert mock_run.call_count == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user