RunnerManager working (dynamic creation of RUNNER_DICT)

This commit is contained in:
Daniel 2023-12-05 20:39:05 +01:00
parent cf3672ef4b
commit 7ac62a6e80
3 changed files with 19 additions and 19 deletions

View file

@ -1,28 +1,28 @@
# should replace static RUNNER_DICT
# WIP
import importlib
import re
from pathlib import Path
from typing import TYPE_CHECKING
from icecream import ic
if TYPE_CHECKING:
from abratest.env_manager import EnvFile, EnvManager
from abratest.runner import Runner
PATTERN = re.compile("Runner.+")
class RunnerManager:
def __init__(self, env_files: list["EnvFile"]):
pass
def __init__(self, recipes_dir: Path):
RUNNER_DICT_NEW = dict()
root = Path("src")
ic(root.resolve())
for module_path in root.rglob("*/runner*.py"):
module_path = module_path.as_posix().replace("/", ".").replace(".py", "")
ic(module_path)
module = importlib.import_module(module_path)
ic(dir(module))
# exit()
# ic(RUNNER_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()