e2e_tests/abratest/runner_manager.py

28 lines
904 B
Python

# should replace static RUNNER_DICT
import importlib
import re
from pathlib import Path
from icecream import ic
from abratest.runner import Runner
PATTERN = re.compile("Runner.+")
class RunnerManager:
def __init__(self, recipes_dir: Path):
RUNNER_DICT_NEW = dict()
for module_path in recipes_dir.rglob("*/runner*.py"):
rel_path = module_path.relative_to(recipes_dir).as_posix().replace("/", ".").replace(".py", "")
ic(rel_path)
module = importlib.import_module(rel_path)
runner_class_names = [name for name in dir(module) if PATTERN.match(name)]
assert len(runner_class_names) == 1
runner_class_name = runner_class_names[0]
RunnerClass: type[Runner] = getattr(module, runner_class_name)
RUNNER_DICT_NEW[RunnerClass.name] = RunnerClass
print(RUNNER_DICT_NEW)
exit()