Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(include_launch_description): only check required arguments in the local launch file #746

Open
wants to merge 10 commits into
base: rolling
Choose a base branch
from
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