2
0
forked from awendt/pyrelacs

[app][repros] adding nix file and checks

This commit is contained in:
wendtalexander 2024-09-27 14:20:18 +02:00
parent a748385335
commit 7d3224f351

View File

@ -4,6 +4,7 @@ import ast
import pathlib import pathlib
from IPython import embed from IPython import embed
import nixio as nix
from pyrelacs.util.logging import config_logging from pyrelacs.util.logging import config_logging
log = config_logging() log = config_logging()
@ -13,22 +14,24 @@ class Repro:
def __init__(self) -> None: def __init__(self) -> None:
pass pass
def run_repro(self, name: str, file: pathlib.Path, *args, **kwargs) -> None: def run_repro(
self, nix_file: nix.File, name: str, file: pathlib.Path, *args, **kwargs
) -> None:
spec = importlib.util.spec_from_file_location("rep", file) spec = importlib.util.spec_from_file_location("rep", file)
if not spec: if not spec:
log.error("Could not load the repro") log.error("Could not load the file")
else: else:
module = importlib.util.module_from_spec(spec) module = importlib.util.module_from_spec(spec)
if not module: if not module:
log.error("Could not load Class of the repro") log.error("Could not load the module of the repro")
else: else:
sys.modules[name] = module sys.modules[name] = module
spec.loader.exec_module(module) spec.loader.exec_module(module)
if hasattr(module, name): if hasattr(module, name):
rep_class = getattr(module, name) rep_class = getattr(module, name)
rep_class.run() rep_class.run(nix_file)
else: else:
raise AttributeError(f"{name} has no run function") raise AttributeError(f"{file.name} has no {name} class")
def names_of_repros(self): def names_of_repros(self):
file_path_cur = pathlib.Path(__file__).parent file_path_cur = pathlib.Path(__file__).parent