forked from clan/clan-core
enable more linting
This commit is contained in:
parent
7ae02d86af
commit
26e3e3872c
@ -16,13 +16,14 @@ find = {}
|
||||
test_driver = ["py.typed"]
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py311"
|
||||
line-length = 88
|
||||
|
||||
select = ["E", "F", "I", "U", "N"]
|
||||
select = ["E", "F", "I", "U", "N", "RUF"]
|
||||
ignore = ["E501"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.10"
|
||||
python_version = "3.11"
|
||||
warn_redundant_casts = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_defs = true
|
||||
|
@ -50,7 +50,7 @@ def merge(a: dict, b: dict, path: list[str] = []) -> dict:
|
||||
for key in b:
|
||||
if key in a:
|
||||
if isinstance(a[key], dict) and isinstance(b[key], dict):
|
||||
merge(a[key], b[key], path + [str(key)])
|
||||
merge(a[key], b[key], [*path, str(key)])
|
||||
elif isinstance(a[key], list) and isinstance(b[key], list):
|
||||
a[key].extend(b[key])
|
||||
elif a[key] != b[key]:
|
||||
|
@ -14,7 +14,7 @@ async def add_flake(path: Path) -> Dict[str, CmdOut]:
|
||||
# TODO: Make this atomic
|
||||
lines: set = set()
|
||||
if user_history_file().exists():
|
||||
with open(user_history_file(), "r") as f:
|
||||
with open(user_history_file()) as f:
|
||||
lines = set(f.readlines())
|
||||
lines.add(str(path))
|
||||
with open(user_history_file(), "w") as f:
|
||||
|
@ -9,7 +9,7 @@ def list_history() -> list[Path]:
|
||||
if not user_history_file().exists():
|
||||
return []
|
||||
# read path lines from history file
|
||||
with open(user_history_file(), "r") as f:
|
||||
with open(user_history_file()) as f:
|
||||
lines = f.readlines()
|
||||
return [Path(line.strip()) for line in lines]
|
||||
|
||||
|
@ -49,23 +49,22 @@ def deploy_nixos(hosts: HostGroup, clan_dir: Path) -> None:
|
||||
if target_user:
|
||||
target_host = f"{target_user}@{target_host}"
|
||||
extra_args = h.meta.get("extra_args", [])
|
||||
cmd = (
|
||||
["nixos-rebuild", "switch"]
|
||||
+ extra_args
|
||||
+ [
|
||||
"--fast",
|
||||
"--option",
|
||||
"keep-going",
|
||||
"true",
|
||||
"--option",
|
||||
"accept-flake-config",
|
||||
"true",
|
||||
"--build-host",
|
||||
"",
|
||||
"--flake",
|
||||
f"{path}#{flake_attr}",
|
||||
]
|
||||
)
|
||||
cmd = [
|
||||
"nixos-rebuild",
|
||||
"switch",
|
||||
*extra_args,
|
||||
"--fast",
|
||||
"--option",
|
||||
"keep-going",
|
||||
"true",
|
||||
"--option",
|
||||
"accept-flake-config",
|
||||
"true",
|
||||
"--build-host",
|
||||
"",
|
||||
"--flake",
|
||||
f"{path}#{flake_attr}",
|
||||
]
|
||||
if target_host:
|
||||
cmd.extend(["--target-host", target_host])
|
||||
ret = h.run(cmd, check=False)
|
||||
|
@ -12,7 +12,7 @@ from .errors import ClanError
|
||||
|
||||
@deal.raises(ClanError)
|
||||
def nix_command(flags: list[str]) -> list[str]:
|
||||
return ["nix", "--extra-experimental-features", "nix-command flakes"] + flags
|
||||
return ["nix", "--extra-experimental-features", "nix-command flakes", *flags]
|
||||
|
||||
|
||||
def nix_flake_show(flake_url: str | Path) -> list[str]:
|
||||
@ -68,19 +68,17 @@ def nix_eval(flags: list[str]) -> list[str]:
|
||||
)
|
||||
if os.environ.get("IN_NIX_SANDBOX"):
|
||||
with tempfile.TemporaryDirectory() as nix_store:
|
||||
return (
|
||||
default_flags
|
||||
+ [
|
||||
"--override-input",
|
||||
"nixpkgs",
|
||||
str(nixpkgs_source()),
|
||||
# --store is required to prevent this error:
|
||||
# error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted
|
||||
"--store",
|
||||
nix_store,
|
||||
]
|
||||
+ flags
|
||||
)
|
||||
return [
|
||||
*default_flags,
|
||||
"--override-input",
|
||||
"nixpkgs",
|
||||
str(nixpkgs_source()),
|
||||
# --store is required to prevent this error:
|
||||
# error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted
|
||||
"--store",
|
||||
nix_store,
|
||||
*flags,
|
||||
]
|
||||
return default_flags + flags
|
||||
|
||||
|
||||
@ -96,7 +94,7 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
|
||||
[
|
||||
"shell",
|
||||
"--inputs-from",
|
||||
f"{str(nixpkgs_flake())}",
|
||||
f"{nixpkgs_flake()!s}",
|
||||
]
|
||||
)
|
||||
+ wrapped_packages
|
||||
|
@ -28,7 +28,7 @@ def upload_secrets(machine: Machine) -> None:
|
||||
" ".join(["ssh"] + ssh_cmd[2:]),
|
||||
"-az",
|
||||
"--delete",
|
||||
f"{str(tempdir)}/",
|
||||
f"{tempdir!s}/",
|
||||
f"{host.user}@{host.host}:{machine.secrets_upload_directory}/",
|
||||
],
|
||||
),
|
||||
|
@ -456,7 +456,8 @@ class Host:
|
||||
else:
|
||||
bash_cmd += cmd
|
||||
# FIXME we assume bash to be present here? Should be documented...
|
||||
ssh_cmd = self.ssh_cmd(verbose_ssh=verbose_ssh) + [
|
||||
ssh_cmd = [
|
||||
*self.ssh_cmd(verbose_ssh=verbose_ssh),
|
||||
"--",
|
||||
f"{sudo}bash -c {quote(bash_cmd)} -- {' '.join(map(quote, bash_args))}",
|
||||
]
|
||||
@ -497,7 +498,7 @@ class Host:
|
||||
if verbose_ssh or self.verbose_ssh:
|
||||
ssh_opts.extend(["-v"])
|
||||
|
||||
return ["ssh", ssh_target] + ssh_opts
|
||||
return ["ssh", ssh_target, *ssh_opts]
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
|
@ -21,7 +21,8 @@ def ssh(
|
||||
"-p",
|
||||
password,
|
||||
]
|
||||
_ssh_args = ssh_args + [
|
||||
_ssh_args = [
|
||||
*ssh_args,
|
||||
"ssh",
|
||||
"-o",
|
||||
"UserKnownHostsFile=/dev/null",
|
||||
@ -29,7 +30,7 @@ def ssh(
|
||||
"StrictHostKeyChecking=no",
|
||||
f"{user}@{host}",
|
||||
]
|
||||
cmd = nix_shell(packages, ["torify"] + password_args + _ssh_args)
|
||||
cmd = nix_shell(packages, ["torify", *password_args, *_ssh_args])
|
||||
subprocess.run(cmd)
|
||||
|
||||
|
||||
|
@ -117,9 +117,9 @@ class BuildVmTask(BaseTask):
|
||||
cmd.run(
|
||||
nix_build(
|
||||
[
|
||||
f'{clan_dir}#clanInternals.machines."{system}"."{machine}".config.system.clan.vm.create'
|
||||
f'{clan_dir}#clanInternals.machines."{system}"."{machine}".config.system.clan.vm.create',
|
||||
*self.nix_options,
|
||||
]
|
||||
+ self.nix_options
|
||||
),
|
||||
name="buildvm",
|
||||
)
|
||||
|
@ -25,7 +25,7 @@ markers = ["impure", "with_core"]
|
||||
|
||||
[tool.mypy]
|
||||
plugins = ["deal.mypy"]
|
||||
python_version = "3.10"
|
||||
python_version = "3.11"
|
||||
warn_redundant_casts = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_defs = true
|
||||
@ -53,7 +53,7 @@ module = "setuptools.*"
|
||||
ignore_missing_imports = true
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py311"
|
||||
line-length = 88
|
||||
|
||||
select = ["E", "F", "I", "N"]
|
||||
select = ["E", "F", "I", "U", "N", "RUF"]
|
||||
ignore = ["E501", "E402"]
|
||||
|
@ -11,7 +11,7 @@ log = logging.getLogger(__name__)
|
||||
class Cli:
|
||||
def run(self, args: list[str]) -> argparse.Namespace:
|
||||
parser = create_parser(prog="clan")
|
||||
cmd = shlex.join(["clan"] + args)
|
||||
cmd = shlex.join(["clan", *args])
|
||||
log.debug(f"$ {cmd}")
|
||||
log.debug(f"Caller {get_caller()}")
|
||||
parsed = parser.parse_args(args)
|
||||
|
@ -47,8 +47,8 @@ def test_set_some_option(
|
||||
example_options,
|
||||
"--settings-file",
|
||||
out_file.name,
|
||||
*args,
|
||||
]
|
||||
+ args
|
||||
)
|
||||
json_out = json.loads(open(out_file.name).read())
|
||||
assert json_out == expected
|
||||
|
@ -15,7 +15,7 @@ def test_flake_history_append(
|
||||
api: TestClient, test_flake: FlakeForTest, temporary_home: Path
|
||||
) -> None:
|
||||
response = api.post(
|
||||
f"/api/flake/history?flake_dir={str(test_flake.path)}",
|
||||
f"/api/flake/history?flake_dir={test_flake.path!s}",
|
||||
json={},
|
||||
)
|
||||
assert response.status_code == 200, response.json()
|
||||
@ -34,7 +34,7 @@ def test_flake_history_list(
|
||||
|
||||
# add the test_flake
|
||||
response = api.post(
|
||||
f"/api/flake/history?flake_dir={str(test_flake.path)}",
|
||||
f"/api/flake/history?flake_dir={test_flake.path!s}",
|
||||
json={},
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
|
@ -11,7 +11,7 @@ scripts = { clan-vm-manager = "clan_vm_manager:main" }
|
||||
clan_vm_manager = ["*.glade"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.10"
|
||||
python_version = "3.11"
|
||||
warn_redundant_casts = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_defs = true
|
||||
@ -22,7 +22,7 @@ module = "gi.*"
|
||||
ignore_missing_imports = true
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py311"
|
||||
line-length = 88
|
||||
|
||||
select = ["E", "F", "I", "N"]
|
||||
select = ["E", "F", "I", "N", "RUF", "U"]
|
||||
ignore = ["E501", "E402", "N802"]
|
||||
|
Loading…
Reference in New Issue
Block a user