-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow and manage module namespaces
- Loading branch information
Showing
23 changed files
with
679 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# -*- coding: utf-8 -*- | ||
import abc | ||
import logging | ||
import typing | ||
|
||
if typing.TYPE_CHECKING: | ||
from kiara import Kiara, KiaraModule | ||
from kiara.module_config import KiaraModuleConfig | ||
from kiara.module_mgmt.pipelines import PipelineModuleManagerConfig | ||
from kiara.module_mgmt.python_classes import ( | ||
PythonModuleManager, | ||
PythonModuleManagerConfig, | ||
) | ||
|
||
|
||
log = logging.getLogger("kiara") | ||
|
||
|
||
# extensions | ||
# ------------------------------------------------------------------------ | ||
|
||
|
||
class ModuleManager(abc.ABC): | ||
@classmethod | ||
def from_config( | ||
cls, | ||
config: typing.Union[ | ||
typing.Mapping[str, typing.Any], | ||
"PipelineModuleManagerConfig", | ||
"PythonModuleManagerConfig", | ||
], | ||
) -> "ModuleManager": | ||
|
||
from kiara.module_mgmt.pipelines import ( | ||
PipelineModuleManager, | ||
PipelineModuleManagerConfig, | ||
) | ||
from kiara.module_mgmt.python_classes import ( | ||
PythonModuleManager, | ||
PythonModuleManagerConfig, | ||
) | ||
|
||
if isinstance(config, typing.Mapping): | ||
mm_type = config.get("module_manager_type", None) | ||
if not mm_type: | ||
raise ValueError(f"No module manager type provided in config: {config}") | ||
if mm_type == "python": | ||
config = PythonModuleManagerConfig(**config) | ||
elif mm_type == "pipeline": | ||
config = PipelineModuleManagerConfig(**config) | ||
else: | ||
raise ValueError(f"Invalid module manager type: {mm_type}") | ||
|
||
if config.module_manager_type == "python": | ||
mm: ModuleManager = PythonModuleManager( | ||
**config.dict(exclude={"module_manager_type"}) | ||
) | ||
elif config.module_manager_type == "pipeline": | ||
mm = PipelineModuleManager(**config.dict(exclude={"module_manager_type"})) | ||
|
||
return mm | ||
|
||
@abc.abstractmethod | ||
def get_module_types(self) -> typing.Iterable[str]: | ||
pass | ||
|
||
@abc.abstractmethod | ||
def get_module_class(self, module_type: str) -> typing.Type["KiaraModule"]: | ||
pass | ||
|
||
def create_module_config( | ||
self, module_type: str, module_config: typing.Mapping[str, typing.Any] | ||
) -> "KiaraModuleConfig": | ||
|
||
cls = self.get_module_class(module_type) | ||
config = cls._config_cls(**module_config) | ||
|
||
return config | ||
|
||
def create_module( | ||
self, | ||
kiara: "Kiara", | ||
id: str, | ||
module_type: str, | ||
module_config: typing.Optional[typing.Mapping[str, typing.Any]] = None, | ||
parent_id: typing.Optional[str] = None, | ||
) -> "KiaraModule": | ||
|
||
module_cls = self.get_module_class(module_type) | ||
|
||
module = module_cls( | ||
id=id, parent_id=parent_id, module_config=module_config, kiara=kiara | ||
) | ||
return module | ||
|
||
|
||
class WorkflowManager(object): | ||
def __init__(self, module_manager: "PythonModuleManager"): | ||
|
||
self._module_mgr: "PythonModuleManager" = module_manager | ||
|
||
def create_workflow( | ||
self, | ||
workflow_id: str, | ||
config: typing.Union[str, typing.Mapping[str, typing.Any]], | ||
): | ||
|
||
if isinstance(config, typing.Mapping): | ||
raise NotImplementedError() |
Oops, something went wrong.