Skip to content

Commit

Permalink
added support for depedencies in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
naman108 committed Aug 19, 2023
1 parent f2951e8 commit c7d0ce6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from digitalpy.core.component_management.impl.default_facade import DefaultFacade
from digitalpy.core.digipy_configuration.configuration import Configuration
from digitalpy.core.digipy_configuration.impl.inifile_configuration import InifileConfiguration
from digitalpy.core.main.object_factory import ObjectFactory

MANIFEST = "manifest"
DIGITALPY = "digitalpy"
Expand All @@ -16,13 +17,15 @@
VERSION = "version"
ID = "UUID"
VERSION_DELIMITER = "."

DEPENDENCIES = "dependencies"

class ComponentRegistrationHandler(RegistrationHandler):
"""this class is used to manage component registration"""

registered_components = {}

pending_components = {}

@staticmethod
def discover_components(component_folder_path: PurePath) -> List[str]:
"""this method is used to discover all available components
Expand Down Expand Up @@ -72,32 +75,45 @@ def register_component(
),
f"{''.join([name.capitalize() if name[0].isupper()==False else name for name in component_name.split('_')])}",
)

facade_instance: DefaultFacade = component_facade(
None, None, None, None
ObjectFactory.get_instance("SyncActionMapper"),
ObjectFactory.get_new_instance("request"),
ObjectFactory.get_new_instance("response"),
config
)

if ComponentRegistrationHandler.validate_manifest(
facade_instance.get_manifest(), component_name
):
valid_manifest, pending = ComponentRegistrationHandler.validate_manifest(
facade_instance.get_manifest(), component_name, facade_instance
)
ComponentRegistrationHandler.save_component(facade_instance, component_name)
if valid_manifest and not pending:
facade_instance.register(config)
ComponentRegistrationHandler.register_pending(component_name, config)
return True
elif valid_manifest and pending:
return True
else:
return False
else:
return False
ComponentRegistrationHandler.save_component(facade_instance.get_manifest(), component_name)

return True
except Exception as e:
# must use a print because logger may not be available
print(f"failed to register component: {component_path}, with error: {e}")
return False

@staticmethod
def save_component(manifest: Configuration, component_name: str):
section = manifest.get_section(component_name + MANIFEST, include_meta=True)
ComponentRegistrationHandler.registered_components[section[NAME]] = section
def save_component(facade, component_name: str):
ComponentRegistrationHandler.registered_components[component_name] = facade

@staticmethod
def register_pending(component_name, config):
for facade_instance in ComponentRegistrationHandler.pending_components.pop(component_name, []):
facade_instance.register(config)

@staticmethod
def validate_manifest(manifest: Configuration, component_name: str) -> bool:
def validate_manifest(manifest: Configuration, component_name: str, component_facade) -> bool:
#TODO: determine better way to inform the caller that the manifest is invalid
"""validate that the component is compatible with the current digitalpy version
Expand Down Expand Up @@ -156,4 +172,19 @@ def validate_manifest(manifest: Configuration, component_name: str) -> bool:
):
return False

return True
pending = False

if (
section.get(DEPENDENCIES, None) is not None
and section[DEPENDENCIES] != ""
):
for dependency in section[DEPENDENCIES].split(","):
if dependency not in ComponentRegistrationHandler.registered_components:
pending = True
if ComponentRegistrationHandler.pending_components.get(dependency) is not None:
ComponentRegistrationHandler.pending_components[dependency].append(component_facade)

else:
ComponentRegistrationHandler.pending_components[dependency] = [component_facade]

return True, pending
2 changes: 2 additions & 0 deletions digitalpy/core/main/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(
action_mapper: ActionMapper,
configuration: Configuration,
):
self.request = request
self.response = response
self.action_mapper = action_mapper
self.configuration = configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def make_request(self, action: str, context: str = "", values: dict={}, target_s
Returns:
_type_: _description_
"""
print("making request to service: " + str(self._service_id) + " with action: " + str(action) + " and context: " + str(context) + " and values: " + str(values))
if target_service_name is None:
target_service_name = self._service_id

Expand Down

0 comments on commit c7d0ce6

Please sign in to comment.