saturnin.component.registry¶
Saturnin component registration and discovery.
Services are registered as entry points for their ServiceDescriptor
- i.e. the instance
of ServiceDescriptor
for installed service is returned by EntryPoint.load()
.
The default group for service registration is saturnin.service
, but it’s possible to
install additional service discovery iterators.
Custom service iterator must be a generator that accepts optional uid
in string format,
and yileds importlib.metadata.EntryPoint
instances. If uid
is specified, it must return
only EntryPoint
only for service with given uid
, otherwise it should return all services.
Note
Custom iterator can return objects that are not EntryPoint
instances,
but they MUST implement load()
method that will return ServiceDescriptor
instance.
Custom iterators must be registered as entry points in saturnin.service.iterator
group.
Globals¶
- saturnin.component.registry.service_registry: ServiceRegistry¶
Saturnin service registry
Classes¶
- class saturnin.component.registry.ServiceInfo(*, uid: UUID, name: str, version: str, vendor: UUID, classification: str, description: str, facilities: List[str], api: List[UUID], factory: str, descriptor: str, distribution: str)[source]¶
Bases:
Distinct
Information about service stored in
ServiceRegistry
.- Parameters:
uid (UUID) – Service UID
name (str) – Service name
version (str) – Service version
vendor (UUID) – Service vendor UID
classification (str) – Service classification
description (str) – Service description
facilities (List[str]) – List of service facilities
api (List[UUID]) – List of interfaces provided by service
factory (str) – Service factory specification (entry point)
descriptor (str) – Service descriptor specification (entry point)
distribution (str) – Installed distribution package that contains this service
- as_toml_dict() Dict [source]¶
Returns dictionary with instance data suitable for storage in TOML format (values that are not of basic type are converted to string).
- Return type:
- property descriptor_obj: ServiceDescriptor¶
Service descriptor object. If it’s not assigned directly, then it’s loaded using
descriptor
on first access.
- class saturnin.component.registry.ServiceRegistry(data: Mapping | Sequence | Registry = None)[source]¶
Bases:
Registry
Saturnin service registry.
Holds
ServiceInfo
instances.It is used in two modes:
In full saturnin deployment, the information about services is loaded from TOML file. Service descriptors and factories are loaded on demand.
In standalone service/bundle mode, service information including service desciptors and factories is stored directly by executor script, so there is no dynamic discovery and the whole could be compiled with Nutika.
- Parameters:
data (Union[Mapping, Sequence, Registry]) –
- add(descriptor: ServiceDescriptor, factory: Any, distribution: str) None [source]¶
Direct service registration. Used by systems that does not allow dynamic discovery, for example programs compiled by Nuitka.
- Parameters:
descriptor (ServiceDescriptor) – Service descriptor
factory (Any) – Service factory
distribution (str) – Distribution package name with service
- Return type:
None
- load() None [source]¶
Read information about installed services from previously saved TOML file.
- Return type:
None
- load_from_installed(*, ignore_errors: bool = False) None [source]¶
Populate registry from descriptors of installed services.
- Parameters:
ignore_errors (bool) – When True, errors are ignored, otherwise
Error
is raised.- Return type:
None