update flake lock, add flake diff, add evaluation json
Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
@ -4,10 +4,12 @@
|
||||
|
||||
import logging
|
||||
from argparse import Namespace
|
||||
from pathlib import Path
|
||||
|
||||
from flupdt.cli import parse_inputs
|
||||
from flupdt.common import configure_logger, partition
|
||||
from flupdt.flake_build import build_output
|
||||
from flupdt.flake_diff import compare_derivations
|
||||
from flupdt.flake_eval import evaluate_output
|
||||
from flupdt.flake_show import get_derivations
|
||||
|
||||
@ -20,11 +22,17 @@ def batch_eval(args: Namespace, flake_path: str, derivations: list[str]) -> None
|
||||
:params derivations: list of derivations to run against
|
||||
:returns None
|
||||
"""
|
||||
drv_map = {}
|
||||
for d in derivations:
|
||||
if args.evaluate:
|
||||
evaluate_output(flake_path, d)
|
||||
drv_map[d] = evaluate_output(flake_path, d)
|
||||
if args.build:
|
||||
build_output(flake_path, d)
|
||||
if args.json:
|
||||
with Path.open(args.json, "w+") as f:
|
||||
from json import dump
|
||||
|
||||
dump(drv_map, f)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@ -35,18 +43,54 @@ def main() -> None:
|
||||
"""
|
||||
configure_logger("DEBUG")
|
||||
args = parse_inputs()
|
||||
flake_path = args.flake_path
|
||||
derivations, hydra_jobs = partition(
|
||||
lambda s: s.startswith("hydraJobs"), get_derivations(flake_path)
|
||||
)
|
||||
derivations, hydra_jobs = list(derivations), list(hydra_jobs)
|
||||
logging.info(f"derivations: {list(derivations)}")
|
||||
batch_eval(args, flake_path, derivations)
|
||||
if args.compare_drvs:
|
||||
pre_json_dict = {}
|
||||
post_json_dict = {}
|
||||
from json import load
|
||||
|
||||
with (
|
||||
Path.open(args.compare_pre_json, "r") as pre,
|
||||
Path.open(args.compare_post_json, "r") as post,
|
||||
):
|
||||
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}")
|
||||
|
||||
pre_json_keys = set(pre_json_dict.keys())
|
||||
post_json_keys = set(post_json_dict.keys())
|
||||
|
||||
common_keys_to_eval = pre_json_keys.union(post_json_keys)
|
||||
|
||||
missing_post_keys = pre_json_keys.difference(common_keys_to_eval)
|
||||
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}")
|
||||
if missing_post_keys:
|
||||
logging.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}")
|
||||
|
||||
for output_key in common_keys_to_eval:
|
||||
compare_derivations(args.flake_path, pre_json_dict[output_key], post_json_dict[output_key])
|
||||
|
||||
|
||||
|
||||
if not args.keep_hydra:
|
||||
logging.info("--keep-hydra flag is not specified, removing Hydra jobs")
|
||||
else:
|
||||
batch_eval(args, flake_path, hydra_jobs)
|
||||
flake_path = args.flake_path
|
||||
derivations, hydra_jobs = partition(
|
||||
lambda s: s.startswith("hydraJobs"), get_derivations(flake_path)
|
||||
)
|
||||
derivations, hydra_jobs = list(derivations), list(hydra_jobs)
|
||||
logging.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")
|
||||
else:
|
||||
batch_eval(args, flake_path, hydra_jobs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user