Skip to content

Commit 6fd719c

Browse files
authored
Add examples to ExecuteProcess docs (#525)
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent 026ab0e commit 6fd719c

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

launch/launch/actions/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# imports needed for doctests
1616
import launch
1717
import launch.actions
18+
import launch.conditions
19+
import launch.substitutions
1820

1921
import pytest
2022

@@ -23,5 +25,10 @@
2325
def add_imports_to_doctest_namespace(doctest_namespace):
2426
doctest_namespace['launch'] = launch
2527
doctest_namespace['LaunchDescription'] = launch.LaunchDescription
26-
for x in launch.actions.__all__:
27-
doctest_namespace[x] = getattr(launch.actions, x)
28+
for subpackage in (
29+
launch.actions,
30+
launch.conditions,
31+
launch.substitutions,
32+
):
33+
for x in subpackage.__all__:
34+
doctest_namespace[x] = getattr(subpackage, x)

launch/launch/actions/execute_process.py

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,93 @@
8484

8585
@expose_action('executable')
8686
class ExecuteProcess(Action):
87-
"""Action that begins executing a process and sets up event handlers for the process."""
87+
"""
88+
Action that begins executing a process and sets up event handlers for it.
89+
90+
Simple example:
91+
92+
.. doctest::
93+
94+
>>> ld = LaunchDescription([
95+
... ExecuteProcess(
96+
... cmd=['ls', '-las'],
97+
... name='my_ls_process', # this is optional
98+
... output='both',
99+
... ),
100+
... ])
101+
102+
.. code-block:: xml
103+
104+
<launch>
105+
<executable cmd="ls -las" name="my_ls_process" output="both"/>
106+
</launch>
107+
108+
Substitutions in the command:
109+
110+
.. doctest::
111+
112+
>>> ld = LaunchDescription([
113+
... DeclareLaunchArgument(name='file_path', description='file path to cat'),
114+
... ExecuteProcess(
115+
... # each item of the command arguments' list can be:
116+
... # a string ('cat'),
117+
... # a substitution (`LaunchConfiguration('file_path')`),
118+
... # or a list of string/substitutions
119+
... # (`[LaunchConfiguration('directory'), '/file.txt']`)
120+
... cmd=['cat', LaunchConfiguration('file_path')],
121+
... ),
122+
... ])
123+
124+
.. code-block:: xml
125+
126+
<launch>
127+
<arg name="file_path" description="path of the file to cat"/>
128+
<executable cmd="cat $(var file_path)"/>
129+
</launch>
130+
131+
Optional cli argument:
132+
133+
.. doctest::
134+
135+
>>> ld = LaunchDescription([
136+
... DeclareLaunchArgument(name='open_gui', default_value='False'),
137+
... ExecuteProcess(
138+
... cmd=['my_cmd', '--open-gui'],
139+
... condition=IfCondition(LaunchConfiguration('open_gui')),
140+
... ),
141+
... ExecuteProcess(
142+
... cmd=['my_cmd'],
143+
... condition=UnlessCondition(LaunchConfiguration('open_gui')),
144+
... ),
145+
... ])
146+
147+
.. code-block:: xml
148+
149+
<launch>
150+
<arg name="open_gui" description="when truthy, the gui will be opened"/>
151+
<executable cmd="my_cmd --open-gui" if="$(var open_gui)"/>
152+
<executable cmd="my_cmd" unless="$(var open_gui)"/>
153+
</launch>
154+
155+
Environment variables:
156+
157+
.. doctest::
158+
159+
>>> ld = LaunchDescription([
160+
... ExecuteProcess(
161+
... cmd=['my_cmd'],
162+
... additional_env={'env_variable': 'env_var_value'},
163+
... ),
164+
... ])
165+
166+
.. code-block:: xml
167+
168+
<launch>
169+
<executable cmd="my_cmd">
170+
<env name="env_variable" value="env_var_value"/>
171+
</executable>
172+
</launch>
173+
"""
88174

89175
def __init__(
90176
self,

0 commit comments

Comments
 (0)