ruff: enable warning lints

This commit is contained in:
Jörg Thalheim
2024-10-23 10:20:43 +02:00
committed by Mic92
parent 2f9981c510
commit 4af1954abf
15 changed files with 30 additions and 15 deletions

View File

@@ -167,7 +167,7 @@ def create_identity() -> Identity:
tmpdir = Path(d) tmpdir = Path(d)
private = tmpdir / "identity.secret" private = tmpdir / "identity.secret"
public = tmpdir / "identity.public" public = tmpdir / "identity.public"
subprocess.run(["zerotier-idtool", "generate", private, public]) subprocess.run(["zerotier-idtool", "generate", private, public], check=True)
return Identity(tmpdir) return Identity(tmpdir)

View File

@@ -24,7 +24,7 @@ def main() -> None:
f.write(json.dumps(moon_json)) f.write(json.dumps(moon_json))
f.flush() f.flush()
Path(moons_d).mkdir(parents=True, exist_ok=True) Path(moons_d).mkdir(parents=True, exist_ok=True)
subprocess.run(["zerotier-idtool", "genmoon", f.name], cwd=moons_d) subprocess.run(["zerotier-idtool", "genmoon", f.name], cwd=moons_d, check=True)
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -60,7 +60,7 @@ Examples:
$ clan facts list [MACHINE] $ clan facts list [MACHINE]
Will list facts for the specified machine. Will list facts for the specified machine.
For more detailed information, visit: {help_hyperlink("secrets", "https://docs.clan.lol/getting-started/secrets")} For more detailed information, visit: {help_hyperlink("secrets", "https://docs.clan.lol/getting-started/secrets")}
""" """
), ),
@@ -89,7 +89,7 @@ Examples:
$ clan facts generate $ clan facts generate
Will generate facts for all machines. Will generate facts for all machines.
$ clan facts generate [MACHINE] $ clan facts generate [MACHINE]
Will generate facts for the specified machine. Will generate facts for the specified machine.
@@ -124,7 +124,7 @@ Examples:
$ clan facts upload [MACHINE] $ clan facts upload [MACHINE]
Will upload secrets to a specific machine. Will upload secrets to a specific machine.
For more detailed information, visit: {help_hyperlink("secrets", "https://docs.clan.lol/getting-started/secrets")} For more detailed information, visit: {help_hyperlink("secrets", "https://docs.clan.lol/getting-started/secrets")}
""" """
), ),

View File

@@ -32,7 +32,7 @@ def read_multiline_input(prompt: str = "Finish with Ctrl-D") -> str:
Read multi-line input from stdin. Read multi-line input from stdin.
""" """
print(prompt, flush=True) print(prompt, flush=True)
proc = subprocess.run(["cat"], stdout=subprocess.PIPE, text=True) proc = subprocess.run(["cat"], stdout=subprocess.PIPE, text=True, check=False)
log.info("Input received. Processing...") log.info("Input received. Processing...")
return proc.stdout return proc.stdout

View File

@@ -62,6 +62,7 @@ class SecretStore(SecretStoreBase):
], ],
), ),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
check=False,
).stdout.strip() ).stdout.strip()
) )
for symlink in Path(password_store).glob(f"machines/{self.machine.name}/**/*"): for symlink in Path(password_store).glob(f"machines/{self.machine.name}/**/*"):
@@ -81,6 +82,7 @@ class SecretStore(SecretStoreBase):
], ],
), ),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
check=False,
).stdout.strip() ).stdout.strip()
) )

View File

@@ -15,14 +15,14 @@ cProfile Output Columns Explanation:
- ncalls: The number of calls to the function. This includes both direct and indirect (recursive) calls. - ncalls: The number of calls to the function. This includes both direct and indirect (recursive) calls.
- tottime: The total time spent in the given function alone, excluding time spent in calls to sub-functions. - tottime: The total time spent in the given function alone, excluding time spent in calls to sub-functions.
This measures the function's own overhead and execution time. This measures the function's own overhead and execution time.
- percall (first instance): Represents the average time spent in the function per call, calculated as tottime divided by ncalls. - percall (first instance): Represents the average time spent in the function per call, calculated as tottime divided by ncalls.
This value excludes time spent in sub-function calls, focusing on the function's own processing time. This value excludes time spent in sub-function calls, focusing on the function's own processing time.
- cumtime: The cumulative time spent in this function and all the sub-functions it calls (both directly and indirectly). - cumtime: The cumulative time spent in this function and all the sub-functions it calls (both directly and indirectly).
This includes all execution time within the function, from the start of its invocation to its return, This includes all execution time within the function, from the start of its invocation to its return,
including all calls to other functions and the time those calls take. including all calls to other functions and the time those calls take.
- percall (second instance): Represents the average time per call, including time spent in this function and in all sub-function calls. - percall (second instance): Represents the average time per call, including time spent in this function and in all sub-function calls.

View File

@@ -51,7 +51,7 @@ def ssh(
cmd_args.insert(0, "torify") cmd_args.insert(0, "torify")
cmd = nix_shell(packages, cmd_args) cmd = nix_shell(packages, cmd_args)
subprocess.run(cmd) subprocess.run(cmd, check=True)
def qrcode_scan(picture_file: str) -> str: def qrcode_scan(picture_file: str) -> str:

View File

@@ -88,6 +88,7 @@ class SecretStore(SecretStoreBase):
], ],
), ),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
check=False,
).stdout.strip() ).stdout.strip()
) )
shared_dir = Path(self._password_store_dir) / self.entry_prefix / "shared" shared_dir = Path(self._password_store_dir) / self.entry_prefix / "shared"
@@ -114,6 +115,7 @@ class SecretStore(SecretStoreBase):
], ],
), ),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
check=False,
).stdout.strip() ).stdout.strip()
) )

View File

@@ -243,6 +243,7 @@ def test_flake(
["git", "diff", "--exit-code", "./sops"], ["git", "diff", "--exit-code", "./sops"],
cwd=temporary_home / "test_flake", cwd=temporary_home / "test_flake",
stderr=sp.PIPE, stderr=sp.PIPE,
check=False,
) )
if git_proc.returncode != 0: if git_proc.returncode != 0:
log.error(git_proc.stderr.decode()) log.error(git_proc.stderr.decode())

View File

@@ -9,7 +9,11 @@ class Error(Exception):
def is_valid_age_key(secret_key: str) -> bool: def is_valid_age_key(secret_key: str) -> bool:
# Run the age-keygen command with the -y flag to check the key format # Run the age-keygen command with the -y flag to check the key format
result = subprocess.run( result = subprocess.run(
["age-keygen", "-y"], input=secret_key, capture_output=True, text=True ["age-keygen", "-y"],
input=secret_key,
capture_output=True,
text=True,
check=False,
) )
if result.returncode == 0: if result.returncode == 0:
@@ -25,7 +29,10 @@ def is_valid_ssh_key(secret_key: str, ssh_pub: str) -> bool:
temp.flush() temp.flush()
# Run the ssh-keygen command with the -y flag to check the key format # Run the ssh-keygen command with the -y flag to check the key format
result = subprocess.run( result = subprocess.run(
["ssh-keygen", "-y", "-f", temp.name], capture_output=True, text=True ["ssh-keygen", "-y", "-f", temp.name],
capture_output=True,
text=True,
check=False,
) )
if result.returncode == 0: if result.returncode == 0:

View File

@@ -126,6 +126,7 @@ def sshd(
str(port), str(port),
"true", "true",
], ],
check=False,
).returncode ).returncode
== 0 == 0
): ):

View File

@@ -46,8 +46,8 @@ def test_clan_flake_in_subdir(git_repo: Path, monkeypatch: pytest.MonkeyPatch) -
# change to the clan_flake subdirectory # change to the clan_flake subdirectory
monkeypatch.chdir(git_repo / "clan_flake") monkeypatch.chdir(git_repo / "clan_flake")
# commit files to git # commit files to git
subprocess.run(["git", "add", "."], cwd=git_repo) subprocess.run(["git", "add", "."], cwd=git_repo, check=True)
subprocess.run(["git", "commit", "-m", "init"], cwd=git_repo) subprocess.run(["git", "commit", "-m", "init"], cwd=git_repo, check=True)
# add a new file under ./clan_flake # add a new file under ./clan_flake
(git_repo / "clan_flake" / "test.txt").touch() (git_repo / "clan_flake" / "test.txt").touch()
# commit the file # commit the file

View File

@@ -25,4 +25,4 @@ cmd = [
print("Running:", shlex.join(cmd)) print("Running:", shlex.join(cmd))
subprocess.run(cmd) subprocess.run(cmd, check=True)

View File

@@ -45,6 +45,7 @@ def list_devshells() -> list[str]:
f"{project_root}#devShells.x86_64-linux", f"{project_root}#devShells.x86_64-linux",
], ],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
check=True,
) )
names = json.loads(flake_show.stdout.decode()) names = json.loads(flake_show.stdout.decode())
return names return names

View File

@@ -41,6 +41,7 @@ lint.select = [
"TID", "TID",
"TRY", "TRY",
"U", "U",
"W",
"YTT", "YTT",
] ]
lint.ignore = [ lint.ignore = [