Skip to content

Commit 910745e

Browse files
authored
Merge pull request #108 from blackhold/python313
make compatible with FTS
2 parents d6fe485 + a2e7820 commit 910745e

10 files changed

Lines changed: 233 additions & 73 deletions

File tree

digitalpy/core/component_management/impl/component_registration_handler.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,36 @@ def clear():
3535

3636
@staticmethod
3737
def discover_components(component_folder_path: PurePath) -> List[str]:
38-
"""this method is used to discover all available components
38+
"""Discover valid components.
3939
40-
Args:
41-
component_folder_path (str): the path in which to search for components. the searchable folder should be in the following format:\n
42-
component_folder_path \n
43-
|-- some_component \n
44-
| `-- some_component_facade.py\n
45-
`-- another_component\n
46-
`-- another_component_facade.py\n
47-
Returns:
48-
List[str]: a list of available components in the given path
40+
A valid component must have:
41+
- <component>/<component>_facade.py
42+
- <component>/configuration/manifest.ini
43+
44+
This avoids trying to register legacy/helper folders that look like
45+
components but are not installable DigitalPy components.
4946
"""
5047
potential_components = os.scandir(component_folder_path)
5148
components = []
49+
5250
for potential_component in potential_components:
51+
if not potential_component.is_dir():
52+
continue
53+
5354
facade_path = PurePath(
54-
potential_component.path, potential_component.name + "_facade.py"
55+
potential_component.path,
56+
potential_component.name + "_facade.py",
57+
)
58+
59+
manifest_path = PurePath(
60+
potential_component.path,
61+
"configuration",
62+
"manifest.ini",
5563
)
56-
if os.path.exists(facade_path):
64+
65+
if os.path.exists(facade_path) and os.path.exists(manifest_path):
5766
components.append(PurePath(potential_component.path))
67+
5868
return components
5969

6070
@staticmethod

digitalpy/core/component_management/impl/default_facade.py

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@
2222

2323
class DefaultFacade(Controller):
2424
def __init__(
25-
self,
26-
action_mapping_path: str,
27-
internal_action_mapping_path,
28-
logger_configuration,
29-
log_file_path,
30-
component_name=None,
31-
type_mapping=None,
32-
action_mapper: DefaultActionMapper = None, # type: ignore
33-
base=ModuleType,
34-
request: Request = None, # type: ignore
35-
response: Response = None, # type: ignore
36-
configuration: Configuration = None, # type: ignore
37-
configuration_path_template=None,
38-
tracing_provider_instance=None,
39-
manifest_path=None,
40-
action_flow_path: Optional[str] = None,
41-
object_configuration_paths: Optional[str] = None,
42-
**kwargs,
25+
self,
26+
action_mapping_path: str,
27+
internal_action_mapping_path,
28+
logger_configuration,
29+
log_file_path,
30+
component_name=None,
31+
type_mapping=None,
32+
action_mapper: DefaultActionMapper = None, # type: ignore
33+
base=ModuleType,
34+
request: Request = None, # type: ignore
35+
response: Response = None, # type: ignore
36+
configuration: Configuration = None, # type: ignore
37+
configuration_path_template=None,
38+
tracing_provider_instance=None,
39+
manifest_path=None,
40+
action_flow_path: Optional[str] = None,
41+
object_configuration_paths: Optional[str] = None,
42+
**kwargs,
4343
):
4444
"""_summary_
4545
@@ -177,7 +177,7 @@ def get_configuration_path(self) -> str:
177177
def get_flow_configuration_path(self) -> str:
178178
"""get the flow configuration path for the component"""
179179
return self.action_flow_path
180-
180+
181181
def get_object_configuration_path(self) -> str:
182182
"""get the object configuration path for the component"""
183183
return self.object_configuration_paths
@@ -192,11 +192,17 @@ def get_action_mapper(self) -> DefaultActionMapper:
192192
internal_config,
193193
),
194194
)
195+
195196
def setup(self, **kwargs):
196197
"""setup the component"""
197198
self.action_mapper = self.get_action_mapper()
198199
self._register_type_mapping()
199200

201+
def register(self, config: InifileConfiguration, **kwargs):
202+
"""register the component with the system"""
203+
config.add_configuration(self.action_mapping_path)
204+
self.setup(**kwargs)
205+
200206
def unregister(self, config: InifileConfiguration, **kwargs):
201207
"""unregister the component from the system"""
202208
ObjectFactory.clear_instance(f"{self.component_name.lower()}actionmapper")
@@ -207,28 +213,40 @@ def get_manifest(self, **kwargs):
207213
return self.manifest
208214

209215
def _register_type_mapping(self):
210-
"""any component may or may not have a type mapping defined,
211-
if it does then it should be registered"""
212-
if self.type_mapping:
216+
"""Register optional type mappings.
217+
218+
Some legacy FTS components define type_mapping before the Type component
219+
action mapper is available. That must not abort component registration.
220+
"""
221+
222+
if not self.type_mapping:
223+
return
224+
225+
actionmapper = ObjectFactory.get_instance("SyncActionMapper")
226+
227+
try:
213228
request = ObjectFactory.get_new_instance("request")
214229
request.set_action("RegisterMachineToHumanMapping")
215230
request.set_value("machine_to_human_mapping", self.type_mapping)
216231

217-
actionmapper = ObjectFactory.get_instance("SyncActionMapper")
218232
response = ObjectFactory.get_new_instance("response")
219233
actionmapper.process_action(request, response)
220234

221235
request = ObjectFactory.get_new_instance("request")
222236
request.set_action("RegisterHumanToMachineMapping")
223-
# reverse the mapping and save the reversed mapping
224237
request.set_value(
225-
"human_to_machine_mapping", {k: v for v, k in self.type_mapping.items()}
238+
"human_to_machine_mapping",
239+
{k: v for v, k in self.type_mapping.items()},
226240
)
227241

228-
actionmapper = ObjectFactory.get_instance("SyncActionMapper")
229242
response = ObjectFactory.get_new_instance("response")
230243
actionmapper.process_action(request, response)
231244

245+
except ValueError as exc:
246+
if "No action key found" in str(exc):
247+
return
248+
raise
249+
232250
def accept_visitor(self, node: Node, visitor, **kwargs):
233251
return node.accept_visitor(visitor)
234252

@@ -244,4 +262,4 @@ def __getstate__(self) -> dict:
244262
set_base = tmp.get("base", None)
245263
if set_base is not None:
246264
tmp["base"] = True
247-
return tmp
265+
return tmp

digitalpy/core/impl/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from digitalpy.core.main.impl.default_event_manager import DefaultEventManager
2+
3+
__all__ = ["DefaultEventManager"]

0 commit comments

Comments
 (0)