From 5f1988b26f72642ee9f26bf5d8738b8c97c877a0 Mon Sep 17 00:00:00 2001 From: huyenngn Date: Fri, 15 Mar 2024 13:40:02 +0100 Subject: [PATCH] fix: Raise error when attempting to create duplicate element --- capella_ros_tools/importer.py | 13 ++++--------- docs/source/howtos.rst | 26 ++++++++++++++++---------- docs/source/usage.rst | 20 ++++++++------------ 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/capella_ros_tools/importer.py b/capella_ros_tools/importer.py index eec3cd0..db63369 100644 --- a/capella_ros_tools/importer.py +++ b/capella_ros_tools/importer.py @@ -111,7 +111,8 @@ def _convert_package( def _convert_class( self, pkg_name: str, msg_def: data_model.MessageDef ) -> tuple[dict, list[dict]]: - promise_id = self._register_promise_id(f"{pkg_name}.{msg_def.name}") + promise_id = f"{pkg_name}.{msg_def.name}" + self._promise_ids.add(promise_id) props = [] associations = [] for field_def in msg_def.fields: @@ -176,7 +177,8 @@ def _convert_class( def _convert_enum( self, pkg_name: str, enum_def: data_model.EnumDef ) -> dict: - promise_id = self._register_promise_id(f"{pkg_name}.{enum_def.name}") + promise_id = f"{pkg_name}.{enum_def.name}" + self._promise_ids.add(promise_id) yml = { "promise_id": promise_id, "find": { @@ -199,13 +201,6 @@ def _convert_enum( return yml - def _register_promise_id(self, promise_id: str) -> str: - while promise_id in self._promise_ids: - promise_id += "_" - - self._promise_ids.add(promise_id) - return promise_id - def to_yaml(self, layer_data_uuid: str, sa_data_uuid: str) -> str: """Import ROS messages into a Capella data package.""" logger.info("Generating decl YAML") diff --git a/docs/source/howtos.rst b/docs/source/howtos.rst index 5f2eacc..741e724 100644 --- a/docs/source/howtos.rst +++ b/docs/source/howtos.rst @@ -17,25 +17,29 @@ Import ROS2 Messages: --------------------- .. code-block:: bash - python -m capella_ros_tools import \ + python -m capella_ros_tools \ + import \ -i tests/data/data_model/example_msgs \ - -m tests/data/empty_project_60 -l la \ - --port=5000 --no-deps + -m tests/data/empty_project_60 \ + -l la \ + --no-deps Import ROS2 Messages from Git Repository: ----------------------------------------- .. code-block:: bash - python -m capella_ros_tools import \ + python -m capella_ros_tools \ + import \ -i git+https://github.com/DSD-DBS/dsd-ros-msg-definitions-oss \ - -m tests/data/ empty_project_60 -l la \ - --port=5000 + -m tests/data/ empty_project_60 \ + -l la Export Capella data package: ------------------------------------ .. code-block:: bash - python -m capella_ros_tools export \ + python -m capella_ros_tools \ + export \ -m tests/data/melody_model_60 -l la \ -o tests/data/melody_msgs @@ -43,9 +47,11 @@ Export Capella data package from Git Repository: -------------------------------------------------------- .. code-block:: bash - python -m capella_ros_tools export \ - -m git+https://github.com/DSD-DBS/coffee-machine -l oa \ + python -m capella_ros_tools \ + export \ + -m git+https://github.com/DSD-DBS/coffee-machine \ + -l oa \ -o tests/data/coffee_msgs .. note:: - When exporting Capella enumerations, if the enumeration literal values are not defined in the Capella model, the values will be set to 0, 1, 2, 3, etc. and the value's type will be set to unit8. + When exporting Capella enumerations, if the enumeration literal values are not defined in the Capella model, the values will be assumed to be 0, 1, 2, 3, etc. and the value's type will be set to unit8. diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 62739ad..800fe99 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -14,17 +14,13 @@ Import ROS2 Messages: ---------------------- .. code-block:: bash - python -m capella_ros_tools import -i -m -l -p --no-deps - -* **-i/--input**, import ROS2 messages from -* **-m/--model**, export to Capella model -* **-l/--layer**, use Capella model layer -* **-p/--port**, start Capella model explorer at (optional) -* **--no-deps**, do not import ROS2 dependencies (e.g. std_msgs) (flag) - -.. note:: - The `--port` option can be used to start the Capella model explorer on a specific port. The Capella model viewer can then be downloaded to be viewed at a later time using `wget` eg. `wget http://localhost: -E -r`. + python -m capella_ros_tools import -i -m -l -o --no-deps +* **-i/--input**, import ROS2 messages from path +* **-m/--model**, write to Capella model at path +* **-l/--layer**, use Capella model layer +* **-o/--out**, write generated decl YAML to path (optional) +* **--no-deps**, flag to disable import of ROS2 dependencies (e.g. std_msgs) Export Capella Model (experimental): ------------------------------------ @@ -32,6 +28,6 @@ Export Capella Model (experimental): python -m capella_ros_tools export -m -l -o -* **-m/--model**, import Capella model from +* **-m/--model**, export Capella model from path * **-l/--layer**, use Capella model layer -* **-o/--output**, export ROS2 messages to +* **-o/--output**, write ROS2 messages to