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

Let XML executables/nodes be "required" (like in ROS 1) #751

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion launch/launch/actions/execute_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import Text

from .execute_local import ExecuteLocal

from .shutdown_action import Shutdown
from ..descriptions import Executable
from ..frontend import Entity
from ..frontend import expose_action
Expand Down Expand Up @@ -331,6 +331,16 @@ def parse(
if name is not None:
kwargs['name'] = parser.parse_substitution(name)

if 'on_exit' not in ignore:
on_exit = entity.get_attr('on_exit', optional=True)
if on_exit is not None:
if on_exit == "shutdown":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our style prefers single-quotes:

Suggested change
if on_exit == "shutdown":
if on_exit == 'shutdown':

kwargs['on_exit'] = [Shutdown()]
else:
raise ValueError(
'Attribute on_exit of Entity node expected to be shutdown but got `{}`'
'Other on_exit actions not yet supported'.format(on_exit))

if 'prefix' not in ignore:
prefix = entity.get_attr('launch-prefix', optional=True)
if prefix is not None:
Expand Down
17 changes: 17 additions & 0 deletions launch_xml/test/launch_xml/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import textwrap

from launch import LaunchService
from launch.actions import Shutdown
from launch.frontend import Parser

import pytest
Expand Down Expand Up @@ -67,5 +68,21 @@ def test_executable_wrong_subtag():
assert 'whats_this' in str(excinfo.value)


def test_executable_on_exit():
xml_file = \
"""\
<launch>
<executable cmd="ls" on_exit="shutdown"/>
</launch>
"""
xml_file = textwrap.dedent(xml_file)
root_entity, parser = Parser.load(io.StringIO(xml_file))
ld = parser.parse_description(root_entity)
executable = ld.entities[0]
sub_entities = executable.get_sub_entities()
assert len(sub_entities) == 1
assert isinstance(sub_entities[0], Shutdown)


if __name__ == '__main__':
test_executable()