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