From b8431aded7fb2b546542ed11af0ff3373668d44c Mon Sep 17 00:00:00 2001 From: Thomas Denewiler Date: Tue, 26 Jul 2022 12:17:32 -0700 Subject: [PATCH] Remove setting package file_type as a boolean in ROS discovery plugin. (#439) --- .../plugins/discovery/ros_discovery_plugin.py | 9 +++---- .../test_ros_discovery_plugin.py | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/statick_tool/plugins/discovery/ros_discovery_plugin.py b/statick_tool/plugins/discovery/ros_discovery_plugin.py index 506c3c9a..d3d8b601 100644 --- a/statick_tool/plugins/discovery/ros_discovery_plugin.py +++ b/statick_tool/plugins/discovery/ros_discovery_plugin.py @@ -50,9 +50,8 @@ def scan( and ros_version is not None ): logging.info(" Package is ROS%s.", ros_version) - package["ros"] = True if ros_version == "1": - package["catkin"] = True + package["is_ros1"] = True elif ros_version == "2": distro = os.getenv("ROS_DISTRO") path = os.getenv("PATH") @@ -62,6 +61,7 @@ def scan( package[ "cmake_flags" ] = "-DCMAKE_PREFIX_PATH=" + item.rstrip("/bin") + package["is_ros2"] = True elif os.path.isfile(package_file) and ros_version is not None: with open(package_file, encoding="utf8") as fconfig: try: @@ -71,11 +71,8 @@ def scan( xmltodict.ParsingInterrupted, ) as exc: # No valid XML found, so we are not going to find the build type. - package["ros"] = False logging.warning(" Invalid XML in %s: %s", package_file, exc) return if self.deep_get(output, "package.export.build_type") == "ament_python": logging.info(" Package is ROS%s.", ros_version) - package["ros"] = True - else: - package["ros"] = False + package["is_ros2"] = True diff --git a/tests/plugins/discovery/ros_discovery_plugin/test_ros_discovery_plugin.py b/tests/plugins/discovery/ros_discovery_plugin/test_ros_discovery_plugin.py index 8302a147..e1d52381 100644 --- a/tests/plugins/discovery/ros_discovery_plugin/test_ros_discovery_plugin.py +++ b/tests/plugins/discovery/ros_discovery_plugin/test_ros_discovery_plugin.py @@ -74,7 +74,8 @@ def test_ros_discovery_plugin_scan_valid(): ) os.environ["ROS_VERSION"] = "1" rdp.scan(package, "level") - assert package["ros"] + assert "is_ros1" in package + assert "is_ros2" not in package def test_ros_discovery_plugin_scan_ros2_python_only(): @@ -86,7 +87,8 @@ def test_ros_discovery_plugin_scan_ros2_python_only(): ) os.environ["ROS_VERSION"] = "2" rdp.scan(package, "level") - assert package["ros"] + assert "is_ros2" in package + assert "is_ros1" not in package def test_ros_discovery_plugin_scan_invalid_no_ros_distro(): @@ -98,7 +100,8 @@ def test_ros_discovery_plugin_scan_invalid_no_ros_distro(): ) del os.environ["ROS_VERSION"] rdp.scan(package, "level") - assert not package["ros"] + assert "is_ros1" not in package + assert "is_ros2" not in package def test_ros_discovery_plugin_scan_invalid_badpath(): @@ -109,7 +112,8 @@ def test_ros_discovery_plugin_scan_invalid_badpath(): ) os.environ["ROS_VERSION"] = "1" rdp.scan(package, "level") - assert not package["ros"] + assert "is_ros1" not in package + assert "is_ros2" not in package def test_ros_discovery_plugin_scan_invalid_nocmake(): @@ -122,7 +126,8 @@ def test_ros_discovery_plugin_scan_invalid_nocmake(): ) os.environ["ROS_VERSION"] = "1" rdp.scan(package, "level") - assert not package["ros"] + assert "is_ros1" not in package + assert "is_ros2" not in package def test_ros_discovery_plugin_scan_invalid_packagexml(): @@ -135,7 +140,8 @@ def test_ros_discovery_plugin_scan_invalid_packagexml(): ) os.environ["ROS_VERSION"] = "1" rdp.scan(package, "level") - assert not package["ros"] + assert "is_ros1" not in package + assert "is_ros2" not in package def test_ros_discovery_plugin_ros2_scan_valid(): @@ -152,7 +158,8 @@ def test_ros_discovery_plugin_ros2_scan_valid(): os.environ["ROS_VERSION"] = "2" os.environ["ROS_DISTRO"] = "foxy" rdp.scan(package, "level") - assert package["ros"] + assert "is_ros2" in package + assert "is_ros1" not in package def test_ros_discovery_plugin_ros1_scan_valid(): @@ -164,5 +171,5 @@ def test_ros_discovery_plugin_ros1_scan_valid(): ) os.environ["ROS_VERSION"] = "1" rdp.scan(package, "level") - assert package["ros"] - assert package["catkin"] + assert "is_ros1" in package + assert "is_ros2" not in package