RunnerManager working (dynamic creation of RUNNER_DICT)
This commit is contained in:
parent
cf3672ef4b
commit
7ac62a6e80
3 changed files with 19 additions and 19 deletions
|
|
@ -7,6 +7,7 @@ from abratest.env_manager import EnvFile, EnvManager
|
||||||
from abratest.html_helper import merge_html_files
|
from abratest.html_helper import merge_html_files
|
||||||
from abratest.runner import Runner
|
from abratest.runner import Runner
|
||||||
from abratest.runner_dict import RUNNER_DICT
|
from abratest.runner_dict import RUNNER_DICT
|
||||||
|
from abratest.runner_manager import RunnerManager
|
||||||
from abratest.utils import rmtree
|
from abratest.utils import rmtree
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -20,6 +21,7 @@ class Coordinator:
|
||||||
|
|
||||||
self.DIR = DirManager(output_dir=output_dir, session_id=session_id, recipes_dir=recipes_dir)
|
self.DIR = DirManager(output_dir=output_dir, session_id=session_id, recipes_dir=recipes_dir)
|
||||||
self.ENV = EnvManager(env_paths_list)
|
self.ENV = EnvManager(env_paths_list)
|
||||||
|
runner_manager = RunnerManager(recipes_dir)
|
||||||
|
|
||||||
def setup_test(self) -> None:
|
def setup_test(self) -> None:
|
||||||
logger.info("calling setup_test()")
|
logger.info("calling setup_test()")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from dotenv import dotenv_values
|
||||||
|
|
||||||
from abratest.dir_manager import DirManager
|
from abratest.dir_manager import DirManager
|
||||||
from abratest.runner_dict import RUNNER_DICT
|
from abratest.runner_dict import RUNNER_DICT
|
||||||
from abratest.runner_manager import RunnerManager
|
|
||||||
|
|
||||||
|
|
||||||
class EnvFile(NamedTuple):
|
class EnvFile(NamedTuple):
|
||||||
|
|
@ -26,7 +25,6 @@ class DependencyRule(NamedTuple):
|
||||||
class EnvManager:
|
class EnvManager:
|
||||||
def __init__(self, env_paths_list: list[Path]):
|
def __init__(self, env_paths_list: list[Path]):
|
||||||
self.env_files: list[EnvFile] = self._get_env_files(env_paths_list)
|
self.env_files: list[EnvFile] = self._get_env_files(env_paths_list)
|
||||||
self.runner_manager = RunnerManager(self.env_files)
|
|
||||||
self.dependency_rules: list[DependencyRule] = self._get_dependency_rules(self.env_files)
|
self.dependency_rules: list[DependencyRule] = self._get_dependency_rules(self.env_files)
|
||||||
self.env_files = self.sort_env_files_by_rule(self.env_files, self.dependency_rules)
|
self.env_files = self.sort_env_files_by_rule(self.env_files, self.dependency_rules)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
# should replace static RUNNER_DICT
|
# should replace static RUNNER_DICT
|
||||||
# WIP
|
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from icecream import ic
|
from icecream import ic
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
from abratest.runner import Runner
|
||||||
from abratest.env_manager import EnvFile, EnvManager
|
|
||||||
|
PATTERN = re.compile("Runner.+")
|
||||||
|
|
||||||
|
|
||||||
class RunnerManager:
|
class RunnerManager:
|
||||||
def __init__(self, env_files: list["EnvFile"]):
|
def __init__(self, recipes_dir: Path):
|
||||||
pass
|
RUNNER_DICT_NEW = dict()
|
||||||
|
|
||||||
root = Path("src")
|
for module_path in recipes_dir.rglob("*/runner*.py"):
|
||||||
ic(root.resolve())
|
rel_path = module_path.relative_to(recipes_dir).as_posix().replace("/", ".").replace(".py", "")
|
||||||
for module_path in root.rglob("*/runner*.py"):
|
ic(rel_path)
|
||||||
module_path = module_path.as_posix().replace("/", ".").replace(".py", "")
|
module = importlib.import_module(rel_path)
|
||||||
ic(module_path)
|
runner_class_names = [name for name in dir(module) if PATTERN.match(name)]
|
||||||
module = importlib.import_module(module_path)
|
assert len(runner_class_names) == 1
|
||||||
ic(dir(module))
|
runner_class_name = runner_class_names[0]
|
||||||
# exit()
|
RunnerClass: type[Runner] = getattr(module, runner_class_name)
|
||||||
|
RUNNER_DICT_NEW[RunnerClass.name] = RunnerClass
|
||||||
|
print(RUNNER_DICT_NEW)
|
||||||
# ic(RUNNER_DICT)
|
exit()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue