ModuleOrchestrationLoader
What it is
- A utility loader that discovers and imports
Orchestrationssubclasses located in anorchestrations/package next to a given module’s root. - Intended to dynamically register orchestration classes for a module based on filesystem contents.
Public API
class ModuleOrchestrationLoader@classmethod load_orchestrations(class_: type) -> List[type[Orchestrations]]- Scans
<module_root>/orchestrationsfor Python files (excluding*test.py), imports them, and returns a list of classes that:- are subclasses of
naas_abi_core.orchestrations.Orchestrations.Orchestrations - belong to the same top-level package as
class_ - define a
Newattribute (expected to be a method)
- are subclasses of
- Scans
Configuration/Dependencies
- Depends on:
naas_abi_core.module.ModuleUtils.find_class_module_root_pathto locate the module root directory forclass_naas_abi_core.orchestrations.Orchestrations.Orchestrationsas the base class filternaas_abi_core.utils.Logger.loggerfor debug/error logging
- Filesystem conventions:
- Orchestrations must live in a folder named
orchestrationsunder the module root. - Each orchestration module must be importable as:
f"{class_.__module__}.orchestrations.<filename_without_py>"
- Orchestrations must live in a folder named
Usage
Minimal example (assuming your package layout includes my_pkg/orchestrations/*.py):
from naas_abi_core.module.ModuleOrchestrationLoader import ModuleOrchestrationLoader
# Any class defined under your module/package
from my_pkg.some_module import SomeClass
orchestration_classes = ModuleOrchestrationLoader.load_orchestrations(SomeClass)
for orch_cls in orchestration_classes:
# The loader requires a `New` attribute to exist on each class
orch = orch_cls.New()
Caveats
- Only
.pyfiles are loaded; files ending withtest.pyare skipped. - Only classes whose top-level package matches
class_.__module__.split(".")[0]are included. - Classes missing a
Newattribute are skipped and an error is logged. - If
orchestrations/does not exist, an empty list is returned.