yaml dump支持ordered dict,支持config_info

This commit is contained in:
Xuwznln
2025-07-19 01:54:53 +08:00
parent 862f250e49
commit ebe9e1b1f8
9 changed files with 152298 additions and 325 deletions

View File

@@ -9,6 +9,7 @@ from typing import Any, Dict, List
import yaml
from unilabos.resources.graphio import resource_plr_to_ulab, tree_to_list
from unilabos.ros.msgs.message_converter import msg_converter_manager, ros_action_to_json_schema, String
from unilabos.utils import logger
from unilabos.utils.decorator import singleton
@@ -65,7 +66,9 @@ class Registry:
},
"feedback": {},
"result": {"success": "success"},
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuter, '用于创建或更新物料资源,每次传入多个物料信息。'),
"schema": ros_action_to_json_schema(
self.ResourceCreateFromOuter, "用于创建或更新物料资源,每次传入多个物料信息。"
),
"goal_default": yaml.safe_load(
io.StringIO(get_yaml_from_goal_type(self.ResourceCreateFromOuter.Goal))
),
@@ -86,7 +89,9 @@ class Registry:
},
"feedback": {},
"result": {"success": "success"},
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuterEasy, '用于创建或更新物料资源,每次传入一个物料信息。'),
"schema": ros_action_to_json_schema(
self.ResourceCreateFromOuterEasy, "用于创建或更新物料资源,每次传入一个物料信息。"
),
"goal_default": yaml.safe_load(
io.StringIO(get_yaml_from_goal_type(self.ResourceCreateFromOuterEasy.Goal))
),
@@ -113,7 +118,9 @@ class Registry:
"goal": {},
"feedback": {},
"result": {"latency_ms": "latency_ms", "time_diff_ms": "time_diff_ms"},
"schema": ros_action_to_json_schema(self.EmptyIn, '用于测试延迟的动作,返回延迟时间和时间差。'),
"schema": ros_action_to_json_schema(
self.EmptyIn, "用于测试延迟的动作,返回延迟时间和时间差。"
),
"goal_default": {},
"handles": {},
},
@@ -149,6 +156,7 @@ class Registry:
for i, file in enumerate(files):
with open(file, encoding="utf-8", mode="r") as f:
data = yaml.safe_load(io.StringIO(f.read()))
complete_data = {}
if data:
# 为每个资源添加文件路径信息
for resource_id, resource_info in data.items():
@@ -172,11 +180,21 @@ class Registry:
if len(class_info) and "module" in class_info:
if class_info.get("type") == "pylabrobot":
res_class = get_class(class_info["module"])
if callable(res_class) and not isinstance(res_class, type): # 有的是类,有的是函数,这里暂时只登记函数类的
if callable(res_class) and not isinstance(
res_class, type
): # 有的是类,有的是函数,这里暂时只登记函数类的
res_instance = res_class(res_class.__name__)
print(res_instance)
res_ulr = tree_to_list([resource_plr_to_ulab(res_instance)])
resource_info["config_info"] = res_ulr
resource_info["registry_type"] = "resource"
complete_data[resource_id] = copy.deepcopy(dict(sorted(resource_info.items()))) # 稍后dump到文件
complete_data = dict(sorted(complete_data.items()))
complete_data = copy.deepcopy(complete_data)
if complete_registry:
with open(file, "w", encoding="utf-8") as f:
yaml.dump(complete_data, f, allow_unicode=True, default_flow_style=False, Dumper=NoAliasDumper)
self.resource_type_registry.update(data)
logger.debug(
f"[UniLab Registry] Resource-{current_resource_number} File-{i+1}/{len(files)} "
@@ -462,7 +480,9 @@ class Registry:
# 恢复原有的description信息auto开头的不修改
for action_name, description in old_descriptions.items():
if action_name in device_config["class"]["action_value_mappings"]: # 有一些会被删除
device_config["class"]["action_value_mappings"][action_name]["schema"]["description"] = description
device_config["class"]["action_value_mappings"][action_name]["schema"][
"description"
] = description
device_config["init_param_schema"] = {}
device_config["init_param_schema"]["config"] = self._generate_unilab_json_command_schema(
enhanced_info["init_params"], "__init__"

View File

@@ -1,8 +1,17 @@
OTDeck:
description: Opentrons deck
class:
category:
- deck
class:
module: pylabrobot.resources.opentrons.deck:OTDeck
type: pylabrobot
config_info: []
description: Opentrons deck
file_path: C:/Users/10230/PycharmProjects/Uni-Lab-OS/unilabos/registry/resources/opentrons/deck.yaml
handles: []
icon: ''
init_param_schema: {}
model:
mesh: opentrons_liquid_handler
type: device
mesh: opentrons_liquid_handler
registry_type: resource
version: 1.0.0

View File

@@ -1,5 +1,39 @@
Opentrons_96_adapter_Vb:
description: Opentrons 96 adapter Vb
class:
category:
- plate_adapters
class:
module: pylabrobot.resources.opentrons.plate_adapters:Opentrons_96_adapter_Vb
type: pylabrobot
type: pylabrobot
config_info:
- children: []
class: ''
config:
barcode: null
category: plate_adapter
model: Opentrons_96_adapter_Vb
rotation:
type: Rotation
x: 0
y: 0
z: 0
size_x: 127.76
size_y: 85.48
size_z: 18.55
type: PlateAdapter
data: {}
id: Opentrons_96_adapter_Vb
name: Opentrons_96_adapter_Vb
parent: null
position:
x: 0
y: 0
z: 0
sample_id: null
type: container
description: Opentrons 96 adapter Vb
file_path: C:/Users/10230/PycharmProjects/Uni-Lab-OS/unilabos/registry/resources/opentrons/plate_adapters.yaml
handles: []
icon: ''
init_param_schema: {}
registry_type: resource
version: 1.0.0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,28 +1,35 @@
container:
description: regular organic container
icon: Flask.webp
class:
category:
- container
class:
module: unilabos.resources.container:RegularContainer
type: unilabos
config_info: []
description: regular organic container
file_path: C:/Users/10230/PycharmProjects/Uni-Lab-OS/unilabos/registry/resources/organic/container.yaml
handles:
- handler_key: top
label: top
io_type: target
data_type: fluid
side: NORTH
data_source: handle
data_key: fluid_in
- handler_key: bottom
label: bottom
io_type: source
data_type: fluid
side: SOUTH
data_source: handle
data_key: fluid_out
- handler_key: bind
label: bind
io_type: target
data_type: mechanical
side: SOUTH
data_source: handle
data_key: mechanical_port
- data_key: fluid_in
data_source: handle
data_type: fluid
handler_key: top
io_type: target
label: top
side: NORTH
- data_key: fluid_out
data_source: handle
data_type: fluid
handler_key: bottom
io_type: source
label: bottom
side: SOUTH
- data_key: mechanical_port
data_source: handle
data_type: mechanical
handler_key: bind
io_type: target
label: bind
side: SOUTH
icon: Flask.webp
init_param_schema: {}
registry_type: resource
version: 1.0.0

View File

@@ -1,5 +1,6 @@
import collections.abc
import json
from collections import OrderedDict
from typing import get_origin, get_args
import yaml
@@ -29,6 +30,14 @@ class NoAliasDumper(yaml.SafeDumper):
return True
# 为NoAliasDumper添加OrderedDict的representation方法
def represent_ordereddict(dumper, data):
return dumper.represent_mapping("tag:yaml.org,2002:map", data.items())
# 注册OrderedDict的representer
NoAliasDumper.add_representer(OrderedDict, represent_ordereddict)
class ResultInfoEncoder(json.JSONEncoder):
"""专门用于处理任务执行结果信息的JSON编码器"""