mirror of
https://github.com/tiqi-group/pydase.git
synced 2026-01-02 02:41:19 +01:00
adds serialization and deserialization support for task objects
This commit is contained in:
@@ -351,7 +351,7 @@ class ProxyLoader:
|
||||
) -> Any:
|
||||
# Custom types like Components or DataService classes
|
||||
component_class = cast(
|
||||
type, Deserializer.get_component_class(serialized_object["type"])
|
||||
type, Deserializer.get_service_base_class(serialized_object["type"])
|
||||
)
|
||||
class_bases = (
|
||||
ProxyClassMixin,
|
||||
|
||||
@@ -160,6 +160,12 @@ def get_object_attr_from_path(target_obj: Any, path: str) -> Any:
|
||||
return get_object_by_path_parts(target_obj, path_parts)
|
||||
|
||||
|
||||
def get_task_class() -> type:
|
||||
from pydase.task.task import Task
|
||||
|
||||
return Task
|
||||
|
||||
|
||||
def get_component_classes() -> list[type]:
|
||||
"""
|
||||
Returns references to the component classes in a list.
|
||||
|
||||
@@ -6,7 +6,9 @@ from typing import TYPE_CHECKING, Any, NoReturn, cast
|
||||
import pydase
|
||||
import pydase.components
|
||||
import pydase.units as u
|
||||
from pydase.utils.helpers import get_component_classes
|
||||
from pydase.utils.helpers import (
|
||||
get_component_classes,
|
||||
)
|
||||
from pydase.utils.serialization.types import (
|
||||
SerializedDatetime,
|
||||
SerializedException,
|
||||
@@ -49,9 +51,9 @@ class Deserializer:
|
||||
return handler(serialized_object)
|
||||
|
||||
# Custom types like Components or DataService classes
|
||||
component_class = cls.get_component_class(serialized_object["type"])
|
||||
if component_class:
|
||||
return cls.deserialize_component_type(serialized_object, component_class)
|
||||
service_base_class = cls.get_service_base_class(serialized_object["type"])
|
||||
if service_base_class:
|
||||
return cls.deserialize_data_service(serialized_object, service_base_class)
|
||||
|
||||
return None
|
||||
|
||||
@@ -110,11 +112,11 @@ class Deserializer:
|
||||
raise exception(serialized_object["value"])
|
||||
|
||||
@staticmethod
|
||||
def get_component_class(type_name: str | None) -> type | None:
|
||||
def get_service_base_class(type_name: str | None) -> type | None:
|
||||
for component_class in get_component_classes():
|
||||
if type_name == component_class.__name__:
|
||||
return component_class
|
||||
if type_name == "DataService":
|
||||
if type_name in ("DataService", "Task"):
|
||||
import pydase
|
||||
|
||||
return pydase.DataService
|
||||
@@ -137,7 +139,7 @@ class Deserializer:
|
||||
return property(get, set)
|
||||
|
||||
@classmethod
|
||||
def deserialize_component_type(
|
||||
def deserialize_data_service(
|
||||
cls, serialized_object: SerializedObject, base_class: type
|
||||
) -> Any:
|
||||
def create_proxy_class(serialized_object: SerializedObject) -> type:
|
||||
|
||||
@@ -15,6 +15,7 @@ from pydase.utils.helpers import (
|
||||
get_attribute_doc,
|
||||
get_component_classes,
|
||||
get_data_service_class_reference,
|
||||
get_task_class,
|
||||
is_property_attribute,
|
||||
parse_full_access_path,
|
||||
parse_serialized_key,
|
||||
@@ -281,6 +282,10 @@ class Serializer:
|
||||
if component_base_cls:
|
||||
obj_type = component_base_cls.__name__ # type: ignore
|
||||
|
||||
elif isinstance(obj, get_task_class()):
|
||||
# Check if obj is a pydase task
|
||||
obj_type = "Task"
|
||||
|
||||
# Get the set of DataService class attributes
|
||||
data_service_attr_set = set(dir(get_data_service_class_reference()))
|
||||
# Get the set of the object attributes
|
||||
|
||||
@@ -98,7 +98,9 @@ class SerializedException(SerializedObjectBase):
|
||||
type: Literal["Exception"]
|
||||
|
||||
|
||||
DataServiceTypes = Literal["DataService", "Image", "NumberSlider", "DeviceConnection"]
|
||||
DataServiceTypes = Literal[
|
||||
"DataService", "Image", "NumberSlider", "DeviceConnection", "Task"
|
||||
]
|
||||
|
||||
|
||||
class SerializedDataService(SerializedObjectBase):
|
||||
|
||||
Reference in New Issue
Block a user