|
|
@ -1,3 +1,4 @@ |
|
|
|
import inspect |
|
|
|
from os import getcwd |
|
|
|
|
|
|
|
from alice.runners.pythonrunner import PythonRunner |
|
|
@ -8,12 +9,14 @@ class Factory(): |
|
|
|
def __init__(self, verbose) -> None: |
|
|
|
self.verbose = verbose |
|
|
|
self.runnertypes = self.__load_runners() |
|
|
|
self.runner_configs = {} |
|
|
|
self.runners = {} |
|
|
|
self.workdir = getcwd() |
|
|
|
self.globals = {} |
|
|
|
|
|
|
|
def __load_runners(self): |
|
|
|
# TODO: Runners can be imported via cli too |
|
|
|
# https://git.gyulai.cloud/gyulaid/alice/issues/4 |
|
|
|
# module = __import__("module_file") |
|
|
|
# my_class = getattr(module, "class_name") |
|
|
|
runners = {"python": PythonRunner} |
|
|
@ -25,15 +28,11 @@ class Factory(): |
|
|
|
def set_globals(self, globals): |
|
|
|
self.globals = globals |
|
|
|
|
|
|
|
def update_globals(self, update): |
|
|
|
if "env" in update: |
|
|
|
self.globals["env"].update(update["env"]) |
|
|
|
|
|
|
|
def update_runners(self, config): |
|
|
|
for runnertype, runnerconfig in config.items(): |
|
|
|
if runnertype != "global": |
|
|
|
if (self.verbose): |
|
|
|
print(f"[Alice] Configuring runner {runnertype}") |
|
|
|
print(f"[Alice] Configuring runner: {runnertype}") |
|
|
|
self.get_runner(runnertype).update_config(runnerconfig) |
|
|
|
|
|
|
|
def get_runner(self, runnertype): |
|
|
@ -41,9 +40,14 @@ class Factory(): |
|
|
|
if runnertype in self.runnertypes: |
|
|
|
if (self.verbose): |
|
|
|
print(f"[Alice] Initializing runner: {runnertype}") |
|
|
|
self.runners[runnertype] = self.runnertypes[runnertype](self.workdir, |
|
|
|
self.globals, |
|
|
|
self.verbose) |
|
|
|
params = { |
|
|
|
"workdir": self.workdir, |
|
|
|
"verbose": self.verbose |
|
|
|
} |
|
|
|
print(type(self.runnertypes[runnertype])) |
|
|
|
print(inspect.signature(self.runnertypes[runnertype])) |
|
|
|
print(inspect.getargspec(self.runnertypes[runnertype])) |
|
|
|
self.runners[runnertype] = self.runnertypes[runnertype](params, self.globals) |
|
|
|
else: |
|
|
|
raise ConfigException(f"Invalid runner type: {runnertype}") |
|
|
|
return self.runners[runnertype] |
|
|
|