From 9183140cd494e7783eb8512ae26d926cf0ce1ab2 Mon Sep 17 00:00:00 2001 From: Cameron Miller Date: Fri, 23 Jul 2021 15:09:47 -0700 Subject: [PATCH 1/7] Added launch-prefix-filter argument with passing to launch via launch configuration Signed-off-by: Cameron Miller --- ros2launch/ros2launch/api/api.py | 9 +++++++++ ros2launch/ros2launch/command/launch.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/ros2launch/ros2launch/api/api.py b/ros2launch/ros2launch/api/api.py index 05c4e3c2..c22f7c34 100644 --- a/ros2launch/ros2launch/api/api.py +++ b/ros2launch/ros2launch/api/api.py @@ -156,6 +156,15 @@ def launch_a_launch_file( if args is not None and args.launch_prefix is not None and len(args.launch_prefix) > 0: launch_file_arguments.append(f'launch-prefix:={args.launch_prefix}') + # Pass launch prefix filter as a forward-slash separated list + if args is not None and args.launch_prefix_filter is not None: + filter_str = '' + for exec_str in args.launch_prefix_filter: + filter_str += f'{exec_str}/' + filter_str = filter_str.strip('/') + if len(filter_str): + launch_file_arguments.append(f'launch-prefix-filter:={filter_str}') + launch_service = launch.LaunchService( argv=launch_file_arguments, noninteractive=noninteractive, diff --git a/ros2launch/ros2launch/command/launch.py b/ros2launch/ros2launch/command/launch.py index 225489dd..ef668f1a 100644 --- a/ros2launch/ros2launch/command/launch.py +++ b/ros2launch/ros2launch/command/launch.py @@ -97,6 +97,13 @@ def add_arguments(self, parser, cli_name): 'Command must be wrapped in quotes if it contains spaces ' "(e.g. --launch-prefix 'xterm -e gdb -ex run --args')." ) + parser.add_argument( + '--launch-prefix-filter', + nargs='+', + default=[], + help=('Filter which executables the --launch-prefix is applied ' + 'to by their executable name.') + ) arg = parser.add_argument( 'package_name', help='Name of the ROS package which contains the launch file') From 615aa3ba6d2d29303fbbcc84b114ef0118921941 Mon Sep 17 00:00:00 2001 From: Cameron Miller Date: Tue, 17 Aug 2021 23:43:14 +0000 Subject: [PATCH 2/7] Modify launch prefix filter argument to be a regex pattern Signed-off-by: Cameron Miller Signed-off-by: Cameron Miller Signed-off-by: Cameron Miller --- ros2launch/ros2launch/api/api.py | 12 +++--------- ros2launch/ros2launch/command/launch.py | 11 +++++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ros2launch/ros2launch/api/api.py b/ros2launch/ros2launch/api/api.py index c22f7c34..2a4acc8e 100644 --- a/ros2launch/ros2launch/api/api.py +++ b/ros2launch/ros2launch/api/api.py @@ -153,17 +153,11 @@ def launch_a_launch_file( # If 'launch-prefix' launch file argument is also provided in the user input, # the 'launch-prefix' option is applied since the last duplicate argument is used - if args is not None and args.launch_prefix is not None and len(args.launch_prefix) > 0: + if args.launch_prefix is not None and len(args.launch_prefix): launch_file_arguments.append(f'launch-prefix:={args.launch_prefix}') - # Pass launch prefix filter as a forward-slash separated list - if args is not None and args.launch_prefix_filter is not None: - filter_str = '' - for exec_str in args.launch_prefix_filter: - filter_str += f'{exec_str}/' - filter_str = filter_str.strip('/') - if len(filter_str): - launch_file_arguments.append(f'launch-prefix-filter:={filter_str}') + if args.launch_prefix_filter is not None and len(args.launch_prefix_filter): + launch_file_arguments.append(f'launch-prefix-filter:={args.launch_prefix_filter}') launch_service = launch.LaunchService( argv=launch_file_arguments, diff --git a/ros2launch/ros2launch/command/launch.py b/ros2launch/ros2launch/command/launch.py index ef668f1a..64f17bec 100644 --- a/ros2launch/ros2launch/command/launch.py +++ b/ros2launch/ros2launch/command/launch.py @@ -99,10 +99,9 @@ def add_arguments(self, parser, cli_name): ) parser.add_argument( '--launch-prefix-filter', - nargs='+', - default=[], - help=('Filter which executables the --launch-prefix is applied ' - 'to by their executable name.') + type=str, + help=('Regex pattern for filtering which executables the --launch-prefix is applied ' + 'to by matching the executable name.') ) arg = parser.add_argument( 'package_name', @@ -160,6 +159,10 @@ def main(self, *, parser, args): raise RuntimeError('unexpected mode') launch_arguments.extend(args.launch_arguments) + if args.launch_prefix is None and args.launch_prefix_filter is not None: + raise RuntimeError( + "--launch-prefix must specified if --launch-prefix-filter is provided") + if args.show_all_subprocesses_output: os.environ['OVERRIDE_LAUNCH_PROCESS_OUTPUT'] = 'both' if args.print: From ae037e6c65f138f799e693fe309e2662420ee486 Mon Sep 17 00:00:00 2001 From: Cameron Miller Date: Wed, 18 Aug 2021 22:08:05 +0000 Subject: [PATCH 3/7] Typo fix in error message Signed-off-by: Cameron Miller --- ros2launch/ros2launch/command/launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2launch/ros2launch/command/launch.py b/ros2launch/ros2launch/command/launch.py index 64f17bec..cde23c88 100644 --- a/ros2launch/ros2launch/command/launch.py +++ b/ros2launch/ros2launch/command/launch.py @@ -161,7 +161,7 @@ def main(self, *, parser, args): if args.launch_prefix is None and args.launch_prefix_filter is not None: raise RuntimeError( - "--launch-prefix must specified if --launch-prefix-filter is provided") + "--launch-prefix must be specified if --launch-prefix-filter is provided") if args.show_all_subprocesses_output: os.environ['OVERRIDE_LAUNCH_PROCESS_OUTPUT'] = 'both' From 71ec92779100088e32a1429e07148ebe00173b3d Mon Sep 17 00:00:00 2001 From: Cameron Miller Date: Fri, 3 Sep 2021 10:57:43 -0700 Subject: [PATCH 4/7] Simplify launch prefix argument checking Co-authored-by: Michel Hidalgo Signed-off-by: Cameron Miller --- ros2launch/ros2launch/api/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2launch/ros2launch/api/api.py b/ros2launch/ros2launch/api/api.py index 2a4acc8e..ca8f1fec 100644 --- a/ros2launch/ros2launch/api/api.py +++ b/ros2launch/ros2launch/api/api.py @@ -153,7 +153,7 @@ def launch_a_launch_file( # If 'launch-prefix' launch file argument is also provided in the user input, # the 'launch-prefix' option is applied since the last duplicate argument is used - if args.launch_prefix is not None and len(args.launch_prefix): + if args and args.launch_prefix: launch_file_arguments.append(f'launch-prefix:={args.launch_prefix}') if args.launch_prefix_filter is not None and len(args.launch_prefix_filter): From 984a6f8acc43110a7367bd16c0addc6de36e1168 Mon Sep 17 00:00:00 2001 From: Cameron Miller Date: Fri, 3 Sep 2021 18:14:08 +0000 Subject: [PATCH 5/7] Remove redundant type Signed-off-by: Cameron Miller --- ros2launch/ros2launch/command/launch.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ros2launch/ros2launch/command/launch.py b/ros2launch/ros2launch/command/launch.py index cde23c88..4b99e822 100644 --- a/ros2launch/ros2launch/command/launch.py +++ b/ros2launch/ros2launch/command/launch.py @@ -99,7 +99,6 @@ def add_arguments(self, parser, cli_name): ) parser.add_argument( '--launch-prefix-filter', - type=str, help=('Regex pattern for filtering which executables the --launch-prefix is applied ' 'to by matching the executable name.') ) From ae91d0e273fdf8a224327a814e2f00eec152884c Mon Sep 17 00:00:00 2001 From: Cameron Miller Date: Fri, 3 Sep 2021 11:58:23 -0700 Subject: [PATCH 6/7] Missed launch prefix filter argument check simplification Co-authored-by: Michel Hidalgo Signed-off-by: Cameron Miller --- ros2launch/ros2launch/api/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2launch/ros2launch/api/api.py b/ros2launch/ros2launch/api/api.py index ca8f1fec..3bdb5bd1 100644 --- a/ros2launch/ros2launch/api/api.py +++ b/ros2launch/ros2launch/api/api.py @@ -156,7 +156,7 @@ def launch_a_launch_file( if args and args.launch_prefix: launch_file_arguments.append(f'launch-prefix:={args.launch_prefix}') - if args.launch_prefix_filter is not None and len(args.launch_prefix_filter): + if args and args.launch_prefix_filter: launch_file_arguments.append(f'launch-prefix-filter:={args.launch_prefix_filter}') launch_service = launch.LaunchService( From 220f1b20c94c428488126b96f82d7662bfd4ece9 Mon Sep 17 00:00:00 2001 From: Cameron Miller Date: Fri, 3 Sep 2021 19:07:27 +0000 Subject: [PATCH 7/7] Styling fix Signed-off-by: Cameron Miller --- ros2launch/ros2launch/command/launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2launch/ros2launch/command/launch.py b/ros2launch/ros2launch/command/launch.py index 4b99e822..1767d6e3 100644 --- a/ros2launch/ros2launch/command/launch.py +++ b/ros2launch/ros2launch/command/launch.py @@ -160,7 +160,7 @@ def main(self, *, parser, args): if args.launch_prefix is None and args.launch_prefix_filter is not None: raise RuntimeError( - "--launch-prefix must be specified if --launch-prefix-filter is provided") + '--launch-prefix must be specified if --launch-prefix-filter is provided') if args.show_all_subprocesses_output: os.environ['OVERRIDE_LAUNCH_PROCESS_OUTPUT'] = 'both'