mirror of
https://github.com/ZGCA-Forge/MsgCenterPy.git
synced 2026-03-24 09:39:16 +00:00
Compare commits
5 Commits
0.1.6
...
182c5187a0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
182c5187a0 | ||
|
|
9e6007eb60 | ||
|
|
03b3b1144c | ||
|
|
97c76708cd | ||
|
|
05d33086a9 |
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.10" # Use minimum version for consistency
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@@ -33,27 +33,27 @@ jobs:
|
||||
with:
|
||||
extra_args: --all-files
|
||||
|
||||
# Step 2: Basic build and test with minimum Python version (3.10)
|
||||
# Step 2: Basic build and test
|
||||
basic-build:
|
||||
name: Basic build (Python 3.10, Ubuntu)
|
||||
name: Basic build (Python 3.11, Ubuntu)
|
||||
runs-on: ubuntu-latest
|
||||
needs: [code-format] # Only run after code formatting passes
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Python 3.10
|
||||
- name: Set up Python 3.11
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.10"
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Cache pip dependencies
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ubuntu-pip-3.10-${{ hashFiles('**/pyproject.toml') }}
|
||||
key: ubuntu-pip-3.11-${{ hashFiles('**/pyproject.toml') }}
|
||||
restore-keys: |
|
||||
ubuntu-pip-3.10-
|
||||
ubuntu-pip-3.11-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@@ -173,7 +173,7 @@ jobs:
|
||||
exclude:
|
||||
# Skip the combination we already tested in basic-build
|
||||
- os: ubuntu-latest
|
||||
python-version: "3.10"
|
||||
python-version: "3.11"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
16
.github/workflows/publish.yml
vendored
16
.github/workflows/publish.yml
vendored
@@ -34,7 +34,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.10" # Use minimum version for consistency
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@@ -46,27 +46,27 @@ jobs:
|
||||
with:
|
||||
extra_args: --all-files
|
||||
|
||||
# Step 2: Basic build and test with minimum Python version (3.10)
|
||||
# Step 2: Basic build and test
|
||||
basic-build:
|
||||
name: Basic build (Python 3.10, Ubuntu)
|
||||
name: Basic build (Python 3.11, Ubuntu)
|
||||
runs-on: ubuntu-latest
|
||||
needs: [code-format] # Only run after code formatting passes
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Python 3.10
|
||||
- name: Set up Python 3.11
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.10"
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Cache pip dependencies
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ubuntu-pip-3.10-${{ hashFiles('**/pyproject.toml') }}
|
||||
key: ubuntu-pip-3.11-${{ hashFiles('**/pyproject.toml') }}
|
||||
restore-keys: |
|
||||
ubuntu-pip-3.10-
|
||||
ubuntu-pip-3.11-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@@ -78,7 +78,7 @@ jobs:
|
||||
run: |
|
||||
pytest -v
|
||||
|
||||
# Step 3: ROS2 integration test
|
||||
# Step 3: ROS2 integration test
|
||||
test-with-ros2:
|
||||
name: ROS2 integration test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -5,7 +5,7 @@ A multi-format message conversion system supporting seamless conversion
|
||||
between ROS2, Pydantic, Dataclass, JSON, Dict, YAML and JSON Schema.
|
||||
"""
|
||||
|
||||
__version__ = "0.1.6"
|
||||
__version__ = "0.1.8"
|
||||
__license__ = "Apache-2.0"
|
||||
|
||||
from msgcenterpy.core.envelope import MessageEnvelope, create_envelope
|
||||
|
||||
@@ -277,9 +277,16 @@ class TypeInfo:
|
||||
# Special handling for object types
|
||||
if self.is_object and self.object_fields:
|
||||
properties = {}
|
||||
required_fields = []
|
||||
for field_name, field_info in self.object_fields.items():
|
||||
properties[field_name] = field_info.to_json_schema_property(include_constraints)
|
||||
if field_info.has_constraint(ConstraintType.REQUIRED):
|
||||
required_fields.append(field_name)
|
||||
property_schema["properties"] = properties
|
||||
if required_fields:
|
||||
property_schema["required"] = required_fields
|
||||
if self.field_name and self.field_name != Consts.ELEMENT_TYPE_INFO_SYMBOL:
|
||||
property_schema["title"] = self.field_name
|
||||
|
||||
# Add description
|
||||
if self.original_type:
|
||||
|
||||
@@ -40,11 +40,7 @@ class ROS2MessageInstance(MessageInstance[Any]):
|
||||
interface = (
|
||||
"msg"
|
||||
if ".msg" in module_name
|
||||
else "srv"
|
||||
if ".srv" in module_name
|
||||
else "action"
|
||||
if ".action" in module_name
|
||||
else "msg"
|
||||
else "srv" if ".srv" in module_name else "action" if ".action" in module_name else "msg"
|
||||
)
|
||||
return f"{package}/{interface}/{class_name}" if package and class_name else f"{module_name}.{class_name}"
|
||||
|
||||
@@ -221,10 +217,9 @@ class ROS2MessageInstance(MessageInstance[Any]):
|
||||
# 基础类型的约束将在 field_accessor 中自动添加
|
||||
pass
|
||||
elif isinstance(definition_type, NamespacedType):
|
||||
# 对象类型,标记为对象并提取字段信息
|
||||
type_info.is_object = True
|
||||
type_info.add_constraint(ConstraintType.TYPE_KEEP, True)
|
||||
# 这里可以进一步扩展来提取对象字段信息
|
||||
self._extract_namespaced_type_fields(type_info, definition_type)
|
||||
# 提取元素类型信息
|
||||
if get_element_type:
|
||||
if not isinstance(definition_type, AbstractNestedType):
|
||||
@@ -240,3 +235,33 @@ class ROS2MessageInstance(MessageInstance[Any]):
|
||||
original_type=definition_type.value_type,
|
||||
)
|
||||
self._extract_from_rosidl_definition(type_info.element_type_info)
|
||||
|
||||
def _extract_namespaced_type_fields(self, type_info: TypeInfo, namespaced_type: "NamespacedType") -> None:
|
||||
"""从 NamespacedType(嵌套 ROS2 消息)中提取所有字段信息,填充 object_fields
|
||||
|
||||
递归处理嵌套的消息类型,确保多层嵌套的结构也能正确提取。
|
||||
|
||||
Args:
|
||||
type_info: 要填充 object_fields 的 TypeInfo 对象
|
||||
namespaced_type: rosidl NamespacedType 定义
|
||||
"""
|
||||
msg_cls = import_message_from_namespaced_type(namespaced_type)
|
||||
msg_instance = msg_cls()
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
slots = msg_instance._fields_and_field_types
|
||||
slot_types = msg_instance.SLOT_TYPES
|
||||
|
||||
for field_name, slot_type in zip(slots, slot_types):
|
||||
std_type = TypeConverter.rosidl_definition_to_standard(slot_type)
|
||||
python_type = TypeConverter.standard_to_python_type(std_type)
|
||||
field_type_info = TypeInfo(
|
||||
field_name=field_name,
|
||||
field_path=f"{type_info.field_path}.{field_name}",
|
||||
standard_type=std_type,
|
||||
python_type=python_type,
|
||||
original_type=slot_type,
|
||||
)
|
||||
self._extract_from_rosidl_definition(field_type_info)
|
||||
field_type_info.add_constraint(ConstraintType.REQUIRED, True)
|
||||
type_info.object_fields[field_name] = field_type_info
|
||||
|
||||
@@ -128,9 +128,10 @@ skips = ["B101", "B601"]
|
||||
# ── Version management ────────────────────────────────────────
|
||||
|
||||
[tool.bumpversion]
|
||||
current_version = "0.1.6"
|
||||
current_version = "0.1.8"
|
||||
commit = true
|
||||
tag = true
|
||||
push = true
|
||||
tag_name = "v{new_version}"
|
||||
message = "release: bump version {current_version} → {new_version}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user