Skip to content

Commit

Permalink
fix: Use nested sync
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Mar 11, 2024
1 parent f4c6ae3 commit 792a2ba
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 438 deletions.
2 changes: 1 addition & 1 deletion capella_ros_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def import_msgs(
"-o",
"--output",
type=click.Path(path_type=pathlib.Path, file_okay=False),
default=pathlib.Path.cwd() / "export",
default=pathlib.Path.cwd() / "data-package",
help="Output directory for the .msg files.",
)
def export_capella(
Expand Down
82 changes: 35 additions & 47 deletions capella_ros_tools/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ def _convert_datatype(self, promise_id: str) -> dict:

def _convert_package(
self,
parent: decl.Promise | decl.UUIDReference,
pkg_def: data_model.MessagePkgDef,
) -> list[dict]:
instructions = []
) -> dict:
classes = []
enums = []
packages = []
Expand All @@ -82,17 +80,17 @@ def _convert_package(
for new_pkg in pkg_def.packages:
promise_id = f"{pkg_def.name}.{new_pkg.name}"
self._promise_ids.add(promise_id)
packages.append(
{
"promise_id": promise_id,
"find": {
"name": new_pkg.name,
},
}
)
instructions.extend(
self._convert_package(decl.Promise(promise_id), new_pkg)
)
yml = {
"promise_id": promise_id,
"find": {
"name": new_pkg.name,
},
}

if new_sync := self._convert_package(new_pkg):
yml["sync"] = new_sync

packages.append(yml)

sync = {}
if classes:
Expand All @@ -102,15 +100,7 @@ def _convert_package(
if packages:
sync["packages"] = packages

if sync:
instructions.append(
{
"parent": parent,
"sync": sync,
}
)

return instructions
return sync

def _convert_class(
self, pkg_name: str, msg_def: data_model.MessageDef
Expand Down Expand Up @@ -182,35 +172,33 @@ def _convert_enum(self, enum_def: data_model.EnumDef) -> dict:

def to_yaml(self, layer_data_uuid: str, sa_data_uuid) -> str:
"""Import ROS messages into a Capella data package."""
instructions = self._convert_package(
decl.UUIDReference(helpers.UUIDString(layer_data_uuid)),
self.messages,
)

instructions = [
{
"parent": decl.UUIDReference(
helpers.UUIDString(layer_data_uuid)
),
"sync": self._convert_package(self.messages),
}
]
if needed_types := self._promise_id_refs - self._promise_ids:
datatypes = [
self._convert_datatype(promise_id)
for promise_id in needed_types
]
instructions.extend(
[
{
"parent": decl.UUIDReference(
helpers.UUIDString(sa_data_uuid)
),
"sync": {
"packages": [
{
"promise_id": "root.DataTypes",
"find": {"name": "Data Types"},
}
],
},
},
{
"parent": decl.Promise("root.DataTypes"),
"sync": {"datatypes": datatypes},
instructions.append(
{
"parent": decl.UUIDReference(
helpers.UUIDString(sa_data_uuid)
),
"sync": {
"packages": [
{
"promise_id": "root.DataTypes",
"find": {"name": "Data Types"},
"sync": {"datatypes": datatypes},
}
],
},
]
}
)
return decl.dump(instructions)
4 changes: 2 additions & 2 deletions docs/source/messages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Enum definition
* **Indented Comment Lines:** Comments on a line of their own but indented are added to the description of the last encountered enum literal.
* **Block Comments:** Comments on a line of their own and not indented are added to the description of the next enum definition or the next enum literal definitions until an empty line and the block comment has been used.

.. literalinclude:: ../../tests/data/data_model/example_msgs/package1/msg/SampleEnum.msg
.. literalinclude:: ../../tests/data/data_model/example_msgs/package1/msg/types/SampleEnum.msg
:language: python

Enum and Class Definition
Expand All @@ -72,7 +72,7 @@ Enum and Class Definition
* Comments at the top of the file are added to the class description.
* **Inline Comments:** Comments on the same line as a property or enum literal are directly added to the description of that element.
* **Indented Comment Lines:** Comments on a line of their own but indented are added to the description of the last encountered property or enum literal.
* **Block Comments:** Comments on a line of their own and not indented are added to the descriptions of the next properties or added to the descriptions of the next/current enum until an empty line and the block comment has been used.
* **Block Comments:** Comments on a line of their own and not indented are added to the descriptions of the next properties, enum or enum literal until an empty line and the block comment has been used.

.. code-block:: python
Expand Down
Loading

0 comments on commit 792a2ba

Please sign in to comment.