Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,36 @@ def clear():

@staticmethod
def discover_components(component_folder_path: PurePath) -> List[str]:
"""this method is used to discover all available components
"""Discover valid components.

Args:
component_folder_path (str): the path in which to search for components. the searchable folder should be in the following format:\n
component_folder_path \n
|-- some_component \n
| `-- some_component_facade.py\n
`-- another_component\n
`-- another_component_facade.py\n
Returns:
List[str]: a list of available components in the given path
A valid component must have:
- <component>/<component>_facade.py
- <component>/configuration/manifest.ini

This avoids trying to register legacy/helper folders that look like
components but are not installable DigitalPy components.
"""
potential_components = os.scandir(component_folder_path)
components = []

for potential_component in potential_components:
if not potential_component.is_dir():
continue

facade_path = PurePath(
potential_component.path, potential_component.name + "_facade.py"
potential_component.path,
potential_component.name + "_facade.py",
)

manifest_path = PurePath(
potential_component.path,
"configuration",
"manifest.ini",
)
if os.path.exists(facade_path):

if os.path.exists(facade_path) and os.path.exists(manifest_path):
components.append(PurePath(potential_component.path))

return components

@staticmethod
Expand Down
72 changes: 45 additions & 27 deletions digitalpy/core/component_management/impl/default_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@

class DefaultFacade(Controller):
def __init__(
self,
action_mapping_path: str,
internal_action_mapping_path,
logger_configuration,
log_file_path,
component_name=None,
type_mapping=None,
action_mapper: DefaultActionMapper = None, # type: ignore
base=ModuleType,
request: Request = None, # type: ignore
response: Response = None, # type: ignore
configuration: Configuration = None, # type: ignore
configuration_path_template=None,
tracing_provider_instance=None,
manifest_path=None,
action_flow_path: Optional[str] = None,
object_configuration_paths: Optional[str] = None,
**kwargs,
self,
action_mapping_path: str,
internal_action_mapping_path,
logger_configuration,
log_file_path,
component_name=None,
type_mapping=None,
action_mapper: DefaultActionMapper = None, # type: ignore
base=ModuleType,
request: Request = None, # type: ignore
response: Response = None, # type: ignore
configuration: Configuration = None, # type: ignore
configuration_path_template=None,
tracing_provider_instance=None,
manifest_path=None,
action_flow_path: Optional[str] = None,
object_configuration_paths: Optional[str] = None,
**kwargs,
):
"""_summary_

Expand Down Expand Up @@ -177,7 +177,7 @@ def get_configuration_path(self) -> str:
def get_flow_configuration_path(self) -> str:
"""get the flow configuration path for the component"""
return self.action_flow_path

def get_object_configuration_path(self) -> str:
"""get the object configuration path for the component"""
return self.object_configuration_paths
Expand All @@ -192,11 +192,17 @@ def get_action_mapper(self) -> DefaultActionMapper:
internal_config,
),
)

def setup(self, **kwargs):
"""setup the component"""
self.action_mapper = self.get_action_mapper()
self._register_type_mapping()

def register(self, config: InifileConfiguration, **kwargs):
"""register the component with the system"""
config.add_configuration(self.action_mapping_path)
self.setup(**kwargs)

def unregister(self, config: InifileConfiguration, **kwargs):
"""unregister the component from the system"""
ObjectFactory.clear_instance(f"{self.component_name.lower()}actionmapper")
Expand All @@ -207,28 +213,40 @@ def get_manifest(self, **kwargs):
return self.manifest

def _register_type_mapping(self):
"""any component may or may not have a type mapping defined,
if it does then it should be registered"""
if self.type_mapping:
"""Register optional type mappings.

Some legacy FTS components define type_mapping before the Type component
action mapper is available. That must not abort component registration.
"""

if not self.type_mapping:
return

actionmapper = ObjectFactory.get_instance("SyncActionMapper")

try:
request = ObjectFactory.get_new_instance("request")
request.set_action("RegisterMachineToHumanMapping")
request.set_value("machine_to_human_mapping", self.type_mapping)

actionmapper = ObjectFactory.get_instance("SyncActionMapper")
response = ObjectFactory.get_new_instance("response")
actionmapper.process_action(request, response)

request = ObjectFactory.get_new_instance("request")
request.set_action("RegisterHumanToMachineMapping")
# reverse the mapping and save the reversed mapping
request.set_value(
"human_to_machine_mapping", {k: v for v, k in self.type_mapping.items()}
"human_to_machine_mapping",
{k: v for v, k in self.type_mapping.items()},
)

actionmapper = ObjectFactory.get_instance("SyncActionMapper")
response = ObjectFactory.get_new_instance("response")
actionmapper.process_action(request, response)

except ValueError as exc:
if "No action key found" in str(exc):
return
raise

def accept_visitor(self, node: Node, visitor, **kwargs):
return node.accept_visitor(visitor)

Expand All @@ -244,4 +262,4 @@ def __getstate__(self) -> dict:
set_base = tmp.get("base", None)
if set_base is not None:
tmp["base"] = True
return tmp
return tmp
Empty file added digitalpy/core/impl/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions digitalpy/core/impl/default_event_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from digitalpy.core.main.impl.default_event_manager import DefaultEventManager

__all__ = ["DefaultEventManager"]
Loading
Loading