fix ruff checks (mostly documentation and dead code)
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Utility to extract flake output info using nix flake (show|check)."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
import typing
|
||||
from subprocess import Popen
|
||||
|
||||
from flupdt.common import bash_wrapper
|
||||
|
||||
@ -16,6 +15,12 @@ output_regexes = [
|
||||
|
||||
|
||||
def traverse_json_base(json_dict: dict[str, typing.Any], path: list[str]) -> list[str]:
|
||||
"""Crawls through the flake outputs to get nixos-configuration and derivation types.
|
||||
|
||||
:param json_dict: dict of flake outputs to check
|
||||
:param path: a list of outputs constructed so far
|
||||
:returns the output path list, plus any new paths found
|
||||
"""
|
||||
final_paths = []
|
||||
for key, value in json_dict.items():
|
||||
if isinstance(value, dict):
|
||||
@ -32,10 +37,21 @@ def traverse_json_base(json_dict: dict[str, typing.Any], path: list[str]) -> lis
|
||||
|
||||
|
||||
def traverse_json(json_dict: dict) -> list[str]:
|
||||
"""Crawls through the flake outputs to get nixos-configuration and derivation types.
|
||||
|
||||
:param json_dict: dict of flake outputs to check
|
||||
:returns a list of outputs that can be evaluated
|
||||
"""
|
||||
return traverse_json_base(json_dict, [])
|
||||
|
||||
|
||||
def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
|
||||
"""Gets all derivations in a flake, using check instead of show.
|
||||
|
||||
:param nix_path: path to nix binary
|
||||
:param path_to_flake: path to flake to be checked
|
||||
:returns a list of all valid derivations in the flake
|
||||
"""
|
||||
flake_check = bash_wrapper(f"{nix_path} flake check --verbose --keep-going", path=path_to_flake)
|
||||
if flake_check[2] != 0:
|
||||
logging.warning(
|
||||
@ -55,10 +71,17 @@ def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
|
||||
|
||||
|
||||
def get_derivations(path_to_flake: str) -> list[str]:
|
||||
"""Gets all derivations present in a flake.
|
||||
|
||||
:param path_to_flake: path to flake to be checked
|
||||
:returns a list of all valid derivations in the flake
|
||||
:raises RuntimeError: fails if nix is not present in the PATH
|
||||
"""
|
||||
nix_path = shutil.which("nix")
|
||||
derivations = []
|
||||
if nix_path is None:
|
||||
raise RuntimeError("nix is not available in the PATH, please verify that it is installed")
|
||||
status_msg = "nix is not available in the PATH, please verify that it is installed"
|
||||
raise RuntimeError(status_msg)
|
||||
flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
|
||||
if flake_show[2] != 0:
|
||||
logging.error("flake show returned non-zero exit code")
|
||||
|
Reference in New Issue
Block a user