Skip to content

Commit

Permalink
fix: Sync enum literals
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Apr 16, 2024
1 parent 5d669be commit 7c15177
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
1 change: 0 additions & 1 deletion capella_ros_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def export_capella(
else:
raise click.UsageError("Either --root or --layer must be provided")

output.mkdir(exist_ok=True, parents=True)
exporter.export(current_pkg, output) # type: ignore


Expand Down
2 changes: 1 addition & 1 deletion capella_ros_tools/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def _clean_name(name: str) -> str:

def export(current_pkg: information.DataPkg, current_path: pathlib.Path):
"""Export a Capella data package to ROS messages."""
current_path.mkdir(parents=True, exist_ok=True)
for cls_obj in current_pkg.classes:
fields = []
for prop_obj in cls_obj.owned_properties:
Expand Down Expand Up @@ -76,6 +77,5 @@ def export(current_pkg: information.DataPkg, current_path: pathlib.Path):

for pkg_obj in current_pkg.packages:
pkg_path = current_path / _clean_name(pkg_obj.name)
pkg_path.mkdir(parents=True, exist_ok=True)
export(pkg_obj, pkg_path)
logger.info("Exported package %s to %s", pkg_obj.name, pkg_path)
51 changes: 32 additions & 19 deletions capella_ros_tools/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,23 @@ def _convert_class(
"find": {"name": prop_promise_id},
"set": {
"navigable_members": [decl.Promise(prop_promise_id)],
},
"sync": {
"members": [
{
"_type": "Property",
"type": decl.Promise(promise_id),
"kind": "ASSOCIATION",
"min_card": decl.NewObject(
"LiteralNumericValue", value="1"
),
"max_card": decl.NewObject(
"LiteralNumericValue", value="1"
),
"find": {
"type": decl.Promise(promise_id),
},
"set": {
"_type": "Property",
"kind": "ASSOCIATION",
"min_card": decl.NewObject(
"LiteralNumericValue", value="1"
),
"max_card": decl.NewObject(
"LiteralNumericValue", value="1"
),
},
}
],
},
Expand All @@ -180,23 +186,30 @@ def _convert_enum(
) -> dict[str, t.Any]:
promise_id = f"{pkg_name}.{enum_def.name}"
self._promise_ids[promise_id] = None
literals = []
for literal in enum_def.literals:
literal_yml = {
"find": {
"name": literal.name,
},
"set": {
"description": literal.description,
"value": decl.NewObject(
"LiteralNumericValue", value=literal.value
),
},
}
literals.append(literal_yml)
yml = {
"promise_id": promise_id,
"find": {
"name": enum_def.name,
},
"set": {
"description": enum_def.description,
"literals": [
{
"name": literal.name,
"description": literal.description,
"value": decl.NewObject(
"LiteralNumericValue", value=literal.value
),
}
for literal in enum_def.literals
],
},
"sync": {
"literals": literals,
},
}

Expand Down

0 comments on commit 7c15177

Please sign in to comment.