ModuleOrchestrationLoader
What it is
- A utility loader that discovers and imports orchestration classes (subclasses of
naas_abi_core.orchestrations.Orchestrations) from a module’sorchestrations/directory.
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 orchestration classes that:- are subclasses of
Orchestrations, - belong to the same top-level package as
class_, - define a
Newattribute (expected to be a method).
- are subclasses of
- Scans
Configuration/Dependencies
- Filesystem/layout expectations:
- The target module must have an
orchestrations/folder at the module root returned byfind_class_module_root_path(class_). - Orchestration classes must be defined in
*.pyfiles within that folder.
- The target module must have an
- Imports used:
importlib,osnaas_abi_core.module.ModuleUtils.find_class_module_root_pathnaas_abi_core.orchestrations.Orchestrations.Orchestrationsnaas_abi_core.utils.Logger.logger(debug/error logging)
Usage
from naas_abi_core.module.ModuleOrchestrationLoader import ModuleOrchestrationLoader
# Any class located in the target package; used to locate the package root and module name.
from my_package.some_module import SomeClass
orchestrations = ModuleOrchestrationLoader.load_orchestrations(SomeClass)
for orch_cls in orchestrations:
print(orch_cls.__name__)
Caveats
- Only
.pyfiles are considered; files ending withtest.pyare skipped. - A candidate orchestration class is ignored (with an error log) if it does not define a
Newattribute. - Classes are filtered to the same top-level package as
class_(value.__module__.split(".")[0]must match).