using helper function to get component class names

The type of the DataService instance (and instances of derived classes)
should always be "DataService" unless it is a component.
Also changing some logic.
This commit is contained in:
Mose Müller 2023-08-09 16:15:51 +02:00
parent 304f2a7d91
commit d8aa944e6d
2 changed files with 24 additions and 9 deletions

View File

@ -9,10 +9,14 @@ import rpyc
from loguru import logger
import pydase.units as u
from pydase.data_service.abstract_data_service import AbstractDataService
from pydase.data_service.callback_manager import CallbackManager
from pydase.data_service.task_manager import TaskManager
from pydase.utils.helpers import (
convert_arguments_to_hinted_types,
generate_paths_from_DataService_dict,
get_class_and_instance_attributes,
get_component_class_names,
get_nested_value_by_path_and_key,
get_object_attr_from_path,
parse_list_attr_and_index,
@ -22,10 +26,6 @@ from pydase.utils.warnings import (
warn_if_instance_class_does_not_inherit_from_DataService,
)
from .abstract_data_service import AbstractDataService
from .callback_manager import CallbackManager
from .task_manager import TaskManager
def process_callable_attribute(attr: Any, args: dict[str, Any]) -> Any:
converted_args_or_error_msg = convert_arguments_to_hinted_types(
@ -226,7 +226,7 @@ class DataService(rpyc.Service, AbstractDataService):
if isinstance(value, DataService):
result[key] = {
"type": type(value).__name__
if type(value).__name__ in ("NumberSlider")
if type(value).__name__ in get_component_class_names()
else "DataService",
"value": value.serialize(),
"readonly": False,
@ -237,10 +237,10 @@ class DataService(rpyc.Service, AbstractDataService):
"type": "list",
"value": [
{
"type": "DataService"
if isinstance(item, DataService)
and type(item).__name__ not in ("NumberSlider")
else type(item).__name__,
"type": type(item).__name__
if not isinstance(item, DataService)
or type(item).__name__ in get_component_class_names()
else "DataService",
"value": item.serialize()
if isinstance(item, DataService)
else item,

View File

@ -309,3 +309,18 @@ def parse_list_attr_and_index(attr_string: str) -> tuple[str, Optional[int]]:
attr_name, idx = attr_string[:-1].split("[")
index = int(idx)
return attr_name, index
def get_component_class_names() -> list[str]:
"""
Returns the names of the component classes in a list.
It takes the names from the pydase/components/__init__.py file, so this file should
always be up-to-date with the currently available components.
Returns:
list[str]: List of component class names
"""
import pydase.components
return pydase.components.__all__