From 8b02b9083f017e2a75360546cb8daf8107560a65 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Mon, 30 Sep 2024 09:45:14 +0200 Subject: [PATCH] [repos] adding check for spec.loader --- pyrelacs/repros/repros.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyrelacs/repros/repros.py b/pyrelacs/repros/repros.py index 11c657f..3067e09 100644 --- a/pyrelacs/repros/repros.py +++ b/pyrelacs/repros/repros.py @@ -8,9 +8,9 @@ import nixio as nix import importlib.util from pyrelacs.util.logging import config_logging + log = config_logging() -from IPython import embed class Repro: """ @@ -25,7 +25,6 @@ class Repro: 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) if not spec: log.error("Could not load the file") @@ -35,7 +34,10 @@ class Repro: log.error("Could not load the module of the repro") else: sys.modules[name] = module - spec.loader.exec_module(module) + if spec.loader is not None: + spec.loader.exec_module(module) + else: + log.error(f"{spec.loader} is None") if hasattr(module, name): rep_class = getattr(module, name) rep_class.run(nix_file)