Skip to content

Commit 7c247cf

Browse files
author
Roger Strain
committed
Apply minor updates to address feedback
Distro A; OPSEC #4584 Signed-off-by: Roger Strain <[email protected]>
1 parent 265ed45 commit 7c247cf

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

launch/launch/actions/execute_local.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,6 @@ def on_stdout_received(self, data: bytes) -> None:
507507
def on_stderr_received(self, data: bytes) -> None:
508508
self.__context.emit_event_sync(ProcessStderr(text=data, **self.__process_event_args))
509509

510-
def __expand_substitutions(self, context):
511-
# store packed kwargs for all ProcessEvent based events
512-
self.__process_event_args = {
513-
'action': self,
514-
'name': self.__process_description.final_name,
515-
'cmd': self.__process_description.final_cmd,
516-
'cwd': self.__process_description.final_cwd,
517-
'env': self.__process_description.final_env,
518-
# pid is added to the dictionary in the connection_made() method of the protocol.
519-
}
520-
521510
async def __execute_process(self, context: LaunchContext) -> None:
522511
process_event_args = self.__process_event_args
523512
if process_event_args is None:
@@ -589,8 +578,17 @@ async def __execute_process(self, context: LaunchContext) -> None:
589578

590579
def prepare(self, context: LaunchContext):
591580
"""Prepare the action for execution."""
592-
self.__process_description.apply_context(context)
593-
self.__expand_substitutions(context)
581+
self.__process_description.prepare(self, context)
582+
583+
# store packed kwargs for all ProcessEvent based events
584+
self.__process_event_args = {
585+
'action': self,
586+
'name': self.__process_description.final_name,
587+
'cmd': self.__process_description.final_cmd,
588+
'cwd': self.__process_description.final_cwd,
589+
'env': self.__process_description.final_env,
590+
# pid is added to the dictionary in the connection_made() method of the protocol.
591+
}
594592

595593
def execute(self, context: LaunchContext) -> Optional[List[LaunchDescriptionEntity]]:
596594
"""

launch/launch/descriptions/executable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ def final_env(self):
148148
"""Getter for final_env."""
149149
return self.__final_env
150150

151-
def apply_context(self, context: LaunchContext):
151+
def prepare(self, action: Action, context: LaunchContext):
152152
"""
153153
Prepare an executable description for execution in a given environment.
154154
155155
This does the following:
156156
- performs substitutions on various properties
157-
"""
158-
self.__expand_substitutions(context)
159157
160-
def __expand_substitutions(self, context):
158+
Note that 'action' is not used at this level; it is provided for use
159+
by subclasses which may override this method.
160+
"""
161161
# expand substitutions in arguments to async_execute_process()
162162
cmd = [perform_substitutions(context, x) for x in self.__cmd]
163163
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd

launch/test/launch/test_executable.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,47 @@ def test_executable():
3434

3535
def test_cmd_string_in_list():
3636
exe = Executable(cmd=['ls "my/subdir/with spaces/"'])
37-
exe.apply_context(LaunchContext())
37+
exe.prepare(None, LaunchContext())
3838
assert all(a == b for a, b in zip(exe.final_cmd, ['ls "my/subdir/with spaces/"']))
3939

4040

4141
def test_cmd_strings_in_list():
4242
exe = Executable(cmd=['ls', '"my/subdir/with spaces/"'])
43-
exe.apply_context(LaunchContext())
43+
exe.prepare(None, LaunchContext())
4444
assert all(a == b for a, b in zip(exe.final_cmd, ['ls', '"my/subdir/with spaces/"']))
4545

4646

4747
def test_cmd_multiple_arguments_in_string():
4848
exe = Executable(cmd=['ls', '-opt1', '-opt2', '-opt3'])
49-
exe.apply_context(LaunchContext())
49+
exe.prepare(None, LaunchContext())
5050
assert all(a == b for a, b in zip(exe.final_cmd, ['ls', '-opt1', '-opt2', '-opt3']))
5151

52+
5253
def test_passthrough_properties():
5354
name = 'name'
5455
cwd = 'cwd'
5556
env = {'a': '1'}
5657
exe = Executable(cmd=['test'], name=name, cwd=cwd, env=env)
57-
exe.apply_context(LaunchContext())
58+
exe.prepare(None, LaunchContext())
5859
assert exe.final_name.startswith(name)
5960
assert exe.final_cwd == cwd
6061
assert exe.final_env == env
61-
62+
63+
6264
def test_substituted_properties():
63-
os.environ['EXECUTABLE_TEST_NAME'] = 'name'
64-
os.environ['EXECUTABLE_TEST_CWD'] = 'cwd'
65-
os.environ['EXECUTABLE_TEST_ENVVAR'] = 'var'
66-
os.environ['EXECUTABLE_TEST_ENVVAL'] = 'value'
67-
name = EnvironmentVariable('EXECUTABLE_TEST_NAME')
68-
cwd = EnvironmentVariable('EXECUTABLE_TEST_CWD')
69-
env = {EnvironmentVariable('EXECUTABLE_TEST_ENVVAR'): EnvironmentVariable('EXECUTABLE_TEST_ENVVAL')}
65+
os.environ['EXECUTABLE_NAME'] = 'name'
66+
os.environ['EXECUTABLE_CWD'] = 'cwd'
67+
os.environ['EXECUTABLE_ENVVAR'] = 'var'
68+
os.environ['EXECUTABLE_ENVVAL'] = 'value'
69+
name = EnvironmentVariable('EXECUTABLE_NAME')
70+
cwd = EnvironmentVariable('EXECUTABLE_CWD')
71+
env = {EnvironmentVariable('EXECUTABLE_EV'): EnvironmentVariable('EXECUTABLE_ENVVAL')}
7072
exe = Executable(cmd=['test'], name=name, cwd=cwd, env=env)
71-
exe.apply_context(LaunchContext())
73+
exe.prepare(None, LaunchContext())
7274
assert exe.final_name.startswith('name')
7375
assert exe.final_cwd == 'cwd'
7476
assert exe.final_env == {'var': 'value'}
75-
del os.environ['EXECUTABLE_TEST_NAME']
76-
del os.environ['EXECUTABLE_TEST_CWD']
77-
del os.environ['EXECUTABLE_TEST_ENVVAR']
78-
del os.environ['EXECUTABLE_TEST_ENVVAL']
77+
del os.environ['EXECUTABLE_NAME']
78+
del os.environ['EXECUTABLE_CWD']
79+
del os.environ['EXECUTABLE_ENVVAR']
80+
del os.environ['EXECUTABLE_ENVVAL']

launch/test/launch/test_execute_local.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import pytest
3737

38+
3839
@pytest.mark.parametrize('test_input,expected', [
3940
(None, [True, False]),
4041
({'TEST_NEW_ENV': '2'}, [False, True])

0 commit comments

Comments
 (0)