3535from typing import Tuple
3636from typing import Union
3737
38+ from launch import Action
3839from launch import LaunchContext
3940from launch import SomeSubstitutionsType
4041from launch .descriptions import Executable
@@ -75,7 +76,6 @@ def __init__(
7576 node_namespace : Optional [SomeSubstitutionsType ] = None ,
7677 parameters : Optional [SomeParameters ] = None ,
7778 remappings : Optional [SomeRemapRules ] = None ,
78- arguments : Optional [Iterable [SomeSubstitutionsType ]] = None ,
7979 traits : Optional [Iterable [NodeTrait ]] = None ,
8080 ** kwargs
8181 ) -> None :
@@ -121,7 +121,6 @@ def __init__(
121121 or dictionaries of parameters.
122122 :param: remappings ordered list of 'to' and 'from' string pairs to be
123123 passed to the node as ROS remapping rules
124- :param: arguments list of extra arguments for the node
125124 :param: traits list of special traits of the node
126125 """
127126 if parameters is not None :
@@ -134,7 +133,6 @@ def __init__(
134133 self .__node_namespace = node_namespace
135134 self .__parameters = [] if parameters is None else normalized_params
136135 self .__remappings = [] if remappings is None else list (normalize_remap_rules (remappings ))
137- self .__arguments = arguments
138136 self .__traits = traits
139137
140138 self .__expanded_node_name = self .UNSPECIFIED_NODE_NAME
@@ -169,11 +167,6 @@ def remappings(self):
169167 """Getter for remappings."""
170168 return self .__remappings
171169
172- @property
173- def arguments (self ):
174- """Getter for arguments."""
175- return self .__arguments
176-
177170 @property
178171 def traits (self ):
179172 """Getter for traits."""
@@ -217,14 +210,22 @@ def _get_parameter_rule(self, param: 'Parameter', context: LaunchContext):
217210 name , value = param .evaluate (context )
218211 return f'{ name } :={ yaml .dump (value )} '
219212
220- def prepare (self , context : LaunchContext , executable : Executable ) -> None :
213+ def prepare (self , context : LaunchContext , executable : Executable , action : Action ) -> None :
214+ self ._perform_substitutions (context , executable .cmd )
215+
216+ # Prepare any traits which may be defined for this node
217+ if self .__traits is not None :
218+ for trait in self .__traits :
219+ trait .prepare (self , context , action )
220+
221+ def _perform_substitutions (self , context : LaunchContext , cmd : List ) -> None :
221222 try :
222223 if self .__substitutions_performed :
223224 # This function may have already been called by a subclass' `execute`, for example.
224225 return
225226 self .__substitutions_performed = True
226227 cmd_ext = ['--ros-args' ] # Prepend ros specific arguments with --ros-args flag
227- executable . cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
228+ cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
228229 if self .__node_name is not None :
229230 self .__expanded_node_name = perform_substitutions (
230231 context , normalize_to_list_of_substitutions (self .__node_name ))
@@ -240,7 +241,7 @@ def prepare(self, context: LaunchContext, executable: Executable) -> None:
240241 if expanded_node_namespace is not None :
241242 self .__expanded_node_namespace = expanded_node_namespace
242243 cmd_ext = ['-r' , LocalSubstitution ("ros_specific_arguments['ns']" )]
243- executable . cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
244+ cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
244245 validate_namespace (self .__expanded_node_namespace )
245246 except Exception :
246247 self .__logger .error (
@@ -262,7 +263,7 @@ def prepare(self, context: LaunchContext, executable: Executable) -> None:
262263 param_file_path = self ._create_params_file_from_dict (global_params )
263264 self .__expanded_parameter_arguments .append ((param_file_path , True ))
264265 cmd_ext = ['--params-file' , f'{ param_file_path } ' ]
265- executable . cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
266+ cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
266267 assert os .path .isfile (param_file_path )
267268 # expand parameters too
268269 if self .__parameters is not None :
@@ -287,7 +288,7 @@ def prepare(self, context: LaunchContext, executable: Executable) -> None:
287288 continue
288289 self .__expanded_parameter_arguments .append ((param_argument , is_file ))
289290 cmd_ext = ['--params-file' if is_file else '-p' , f'{ param_argument } ' ]
290- executable . cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
291+ cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
291292 # expand remappings too
292293 global_remaps = context .launch_configurations .get ('ros_remaps' , None )
293294 if global_remaps or self .__remappings :
@@ -303,7 +304,7 @@ def prepare(self, context: LaunchContext, executable: Executable) -> None:
303304 cmd_ext = []
304305 for src , dst in self .__expanded_remappings :
305306 cmd_ext .extend (['-r' , f'{ src } :={ dst } ' ])
306- executable . cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
307+ cmd .extend ([normalize_to_list_of_substitutions (x ) for x in cmd_ext ])
307308 # Prepare the ros_specific_arguments list and add it to the context so that the
308309 # LocalSubstitution placeholders added to the the cmd can be expanded using the contents.
309310 ros_specific_arguments : Dict [str , Union [str , List [str ]]] = {}
@@ -321,4 +322,4 @@ def prepare(self, context: LaunchContext, executable: Executable) -> None:
321322 execute_process_logger .warning (
322323 'there are now at least {} nodes with the name {} created within this '
323324 'launch context' .format (node_name_count , self .node_name )
324- )
325+ )
0 commit comments