Skip to content

Commit

Permalink
feat(include_launch_description): only check required arguments in th…
Browse files Browse the repository at this point in the history
…e local launch file (#1)

* only check arguments with the first inclusion and only search local argument

---------

Signed-off-by: Owen-Liuyuxuan <[email protected]>
Co-authored-by: Owen-Liuyuxuan <[email protected]>
Co-authored-by: Yuxuan Liu <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent f2ee3a8 commit 67138d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions launch/launch/actions/include_launch_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,18 @@ def execute(self, context: LaunchContext) -> List[LaunchDescriptionEntity]:
for arg_name, arg_value in self.launch_arguments
]
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)
)
for argument, ild_actions in declared_launch_arguments:
if argument._conditionally_included or argument.default_value is not None:
continue
argument_names = my_argument_names
if ild_actions is not None:
for ild_action in ild_actions:
argument_names.extend(ild_action._try_get_arguments_names_without_context())
argument_names.extend(
ild_action._try_get_arguments_names_without_context()
)
if argument.name not in argument_names:
raise RuntimeError(
"Included launch description missing required argument '{}' "
Expand Down
17 changes: 12 additions & 5 deletions launch/launch/launch_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_launch_arguments(self, conditional_inclusion=False) -> List[DeclareLaunc
]

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

def process_entities(entities, *, _conditional_inclusion, nested_ild_actions=None):
def process_entities(entities, *, _conditional_inclusion, nested_ild_actions=None,
only_search_local=False):
for entity in entities:
if isinstance(entity, DeclareLaunchArgument):
# Avoid duplicate entries with the same name.
Expand All @@ -139,6 +140,9 @@ def process_entities(entities, *, _conditional_inclusion, nested_ild_actions=Non
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 @@ -151,14 +155,17 @@ def process_entities(entities, *, _conditional_inclusion, nested_ild_actions=Non
process_entities(
entity.describe_sub_entities(),
_conditional_inclusion=False,
nested_ild_actions=next_nested_ild_actions)
nested_ild_actions=next_nested_ild_actions,
only_search_local=only_search_local)
for conditional_sub_entity in entity.describe_conditional_sub_entities():
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

0 comments on commit 67138d3

Please sign in to comment.