Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions launch/launch/descriptions/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""Module for a description of an Executable."""

import os
import pathlib
import re
import shlex
import threading
Expand Down Expand Up @@ -74,9 +75,13 @@ def __init__(
additional_env.
:param arguments: list of extra arguments for the executable
"""
self.__arguments = None if arguments is None else [
argument if isinstance(argument, (str, pathlib.Path, Substitution)) else list(argument)
for argument in arguments
]
self.__cmd = [normalize_to_list_of_substitutions(x) for x in cmd]
self.__cmd += ([] if arguments is None
else [normalize_to_list_of_substitutions(x) for x in arguments])
self.__cmd += ([] if self.__arguments is None
else [normalize_to_list_of_substitutions(x) for x in self.__arguments])
self.__prefix = normalize_to_list_of_substitutions(
LaunchConfiguration('launch-prefix', default='') if prefix is None else prefix
)
Expand All @@ -99,7 +104,6 @@ def __init__(
self.__additional_env.append((
normalize_to_list_of_substitutions(key),
normalize_to_list_of_substitutions(value)))
self.__arguments = arguments
self.__final_cmd: Optional[List[str]] = None
self.__final_cwd: Optional[str] = None
self.__final_env: Optional[Dict[str, str]] = None
Expand Down
16 changes: 16 additions & 0 deletions launch/test/launch/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ def test_cmd_multiple_arguments_in_string():
assert all(a == b for a, b in zip(exe.final_cmd, ['ls', '-opt1', '-opt2', '-opt3']))


def test_arguments_generator_is_preserved():
arguments = (value for value in ['--flag', 'value'])
exe = Executable(cmd=['test'], arguments=arguments)
exe.prepare(LaunchContext(), None)
assert exe.final_cmd == ['test', '--flag', 'value']
assert list(exe.arguments) == ['--flag', 'value']


def test_nested_argument_generator_is_preserved():
argument = (value for value in ['--', 'flag'])
exe = Executable(cmd=['test'], arguments=[argument])
exe.prepare(LaunchContext(), None)
assert exe.final_cmd == ['test', '--flag']
assert exe.arguments == [['--', 'flag']]


def test_passthrough_properties():
name = 'name'
cwd = 'cwd'
Expand Down