exit on failure, add per-class logging
All checks were successful
Check Nix flake / Perform Nix flake checks (ubuntu-latest) (pull_request) Successful in 3m26s
Check flake.lock / Check health of `flake.lock` (pull_request) Successful in 20s
Check Nix flake / Build nix outputs (ubuntu-latest) (pull_request) Successful in 2m21s
Check Nix formatting / Perform Nix format checks (pull_request) Successful in 1m41s

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
2025-03-26 11:22:29 -04:00
parent 4438e93037
commit 607f3f9f76
5 changed files with 42 additions and 31 deletions

View File

@ -4,6 +4,7 @@
import logging
import os
import sys
from argparse import Namespace
from pathlib import Path
@ -14,6 +15,8 @@ from flupdt.flake_diff import compare_derivations
from flupdt.flake_eval import evaluate_output
from flupdt.flake_show import get_derivations
logger = logging.getLogger(__name__)
def batch_eval(args: Namespace, flake_path: str, derivations: list[str]) -> None:
"""Bulk run evaluations or builds on a derivation set.
@ -28,12 +31,14 @@ def batch_eval(args: Namespace, flake_path: str, derivations: list[str]) -> None
if args.evaluate:
drv_map[d] = evaluate_output(flake_path, d)
if args.build:
build_output(flake_path, d)
drv_map[d] = build_output(flake_path, d)
if args.json:
with Path.open(args.json, "w+") as f:
from json import dump
dump(drv_map, f)
if any(x is None for x in drv_map.values()):
sys.exit(1)
def compare_drvs(args: Namespace) -> None:
@ -52,8 +57,8 @@ def compare_drvs(args: Namespace) -> None:
pre_json_dict = load(pre)
post_json_dict = load(post)
logging.debug(f"pre-snapshot derivations: {pre_json_dict}")
logging.debug(f"post-snapshot derivations: {post_json_dict}")
logger.debug(f"pre-snapshot derivations: {pre_json_dict}")
logger.debug(f"post-snapshot derivations: {post_json_dict}")
pre_json_keys = set(pre_json_dict.keys())
post_json_keys = set(post_json_dict.keys())
@ -64,11 +69,11 @@ def compare_drvs(args: Namespace) -> None:
missing_pre_keys = post_json_keys.difference(common_keys_to_eval)
if missing_pre_keys:
logging.warning(f"Following outputs are missing from pre-snapshot: {missing_pre_keys}")
logger.warning(f"Following outputs are missing from pre-snapshot: {missing_pre_keys}")
if missing_post_keys:
logging.warning(f"Following outputs are missing from post-snapshot: {missing_post_keys}")
logger.warning(f"Following outputs are missing from post-snapshot: {missing_post_keys}")
logging.info(f"Evaluating the following outputs for differences: {common_keys_to_eval}")
logger.info(f"Evaluating the following outputs for differences: {common_keys_to_eval}")
out_file: str = os.devnull
if args.compare_output_to_file:
@ -97,11 +102,11 @@ def build_or_eval(args: Namespace) -> None:
lambda s: s.startswith("hydraJobs"), get_derivations(flake_path)
)
derivations, hydra_jobs = list(derivations), list(hydra_jobs)
logging.info(f"derivations: {list(derivations)}")
logger.info(f"derivations: {list(derivations)}")
batch_eval(args, flake_path, derivations)
if not args.keep_hydra:
logging.info("--keep-hydra flag is not specified, removing Hydra jobs")
logger.info("--keep-hydra flag is not specified, removing Hydra jobs")
else:
batch_eval(args, flake_path, hydra_jobs)