Skip to content
Open
5 changes: 4 additions & 1 deletion launch/launch/actions/include_launch_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,12 @@ def execute(self, context: LaunchContext) -> List[Union[SetLaunchConfiguration,
perform_substitutions(context, normalize_to_list_of_substitutions(arg_name))
for arg_name, arg_value in self.launch_arguments
]

try:
declared_launch_arguments = (
launch_description.get_launch_arguments_with_include_launch_description_actions())
launch_description.get_launch_arguments_with_include_launch_description_actions(
only_search_local=True
))
except Exception as exc:
if hasattr(exc, 'add_note'):
exc.add_note(f'while executing {self.describe()}') # type: ignore
Expand Down
26 changes: 19 additions & 7 deletions launch/launch/launch_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def get_launch_arguments(self, conditional_inclusion: bool = False
]

def get_launch_arguments_with_include_launch_description_actions(
self, conditional_inclusion: bool = False
self, conditional_inclusion: bool = False,
only_search_local: bool = False
) -> List[Tuple[DeclareLaunchArgument, List['IncludeLaunchDescription']]]:
"""
Return a list of launch arguments with its associated include launch descriptions actions.
Expand Down Expand Up @@ -130,7 +131,12 @@ def get_launch_arguments_with_include_launch_description_actions(
Tuple[DeclareLaunchArgument, List[IncludeLaunchDescription]]] = []
from .actions import ResetLaunchConfigurations

def process_entities(entities, *, _conditional_inclusion: bool, nested_ild_actions=None):
def process_entities(
entities,
*,
_conditional_inclusion: bool,
nested_ild_actions=None,
only_search_local: bool = False):
for entity in entities:
if isinstance(entity, DeclareLaunchArgument):
# Avoid duplicate entries with the same name.
Expand All @@ -141,6 +147,9 @@ def process_entities(entities, *, _conditional_inclusion: bool, nested_ild_actio
entity._conditionally_included = _conditional_inclusion
entity._conditionally_included |= entity.condition is not None
declared_launch_arguments.append((entity, nested_ild_actions))
if only_search_local:
if isinstance(entity, IncludeLaunchDescription):
continue
if isinstance(entity, ResetLaunchConfigurations):
# Launch arguments after this cannot be set directly by top level arguments
return
Expand All @@ -152,9 +161,10 @@ def process_entities(entities, *, _conditional_inclusion: bool, nested_ild_actio
next_nested_ild_actions.append(entity)
try:
process_entities(
entity.describe_sub_entities(),
_conditional_inclusion=False,
nested_ild_actions=next_nested_ild_actions)
entity.describe_sub_entities(),
_conditional_inclusion=False,
nested_ild_actions=next_nested_ild_actions,
only_search_local=only_search_local)
except Exception as e:
if sys.version_info >= (3, 11):
e.add_note(f'processing sub-entities of entity: {entity}')
Expand All @@ -163,9 +173,11 @@ def process_entities(entities, *, _conditional_inclusion: bool, nested_ild_actio
process_entities(
conditional_sub_entity[1],
_conditional_inclusion=True,
nested_ild_actions=next_nested_ild_actions)
nested_ild_actions=next_nested_ild_actions,
only_search_local=only_search_local)

process_entities(self.entities, _conditional_inclusion=conditional_inclusion)
process_entities(self.entities, _conditional_inclusion=conditional_inclusion,
only_search_local=only_search_local)

return declared_launch_arguments

Expand Down