Skip to content

Commit be36e50

Browse files
authored
Allow for raw path specification in IncludeLaunchDescription (#544)
* Allow for raw path specification in IncludeLaunchDescription Signed-off-by: David V. Lu <[email protected]> * Rename variable, add extra exception case Signed-off-by: David V. Lu <[email protected]> * Use single parameter Signed-off-by: David V. Lu <[email protected]> * Some tests? Signed-off-by: David V. Lu <[email protected]> * Move and consolidate tests Signed-off-by: David V. Lu <[email protected]>
1 parent 54f93b9 commit be36e50

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

launch/launch/actions/include_launch_description.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import List
2020
from typing import Optional
2121
from typing import Tuple
22+
from typing import Union
2223

2324
from .set_launch_configuration import SetLaunchConfiguration
2425
from ..action import Action
@@ -63,7 +64,7 @@ class IncludeLaunchDescription(Action):
6364

6465
def __init__(
6566
self,
66-
launch_description_source: LaunchDescriptionSource,
67+
launch_description_source: Union[LaunchDescriptionSource, SomeSubstitutionsType],
6768
*,
6869
launch_arguments: Optional[
6970
Iterable[Tuple[SomeSubstitutionsType, SomeSubstitutionsType]]
@@ -72,6 +73,8 @@ def __init__(
7273
) -> None:
7374
"""Create an IncludeLaunchDescription action."""
7475
super().__init__(**kwargs)
76+
if not isinstance(launch_description_source, LaunchDescriptionSource):
77+
launch_description_source = AnyLaunchDescriptionSource(launch_description_source)
7578
self.__launch_description_source = launch_description_source
7679
self.__launch_arguments = () if launch_arguments is None else tuple(launch_arguments)
7780

@@ -80,7 +83,7 @@ def parse(cls, entity: Entity, parser: Parser):
8083
"""Return `IncludeLaunchDescription` action and kwargs for constructing it."""
8184
_, kwargs = super().parse(entity, parser)
8285
file_path = parser.parse_substitution(entity.get_attr('file'))
83-
kwargs['launch_description_source'] = AnyLaunchDescriptionSource(file_path)
86+
kwargs['launch_description_source'] = file_path
8487
args = entity.get_attr('arg', data_type=List[Entity], optional=True)
8588
if args is not None:
8689
kwargs['launch_arguments'] = [

launch/test/launch/actions/test_include_launch_description.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from launch.actions import DeclareLaunchArgument
2424
from launch.actions import IncludeLaunchDescription
2525
from launch.actions import SetLaunchConfiguration
26+
from launch.launch_description_sources import PythonLaunchDescriptionSource
2627
from launch.utilities import perform_substitutions
2728

2829
import pytest
@@ -185,3 +186,31 @@ def test_include_launch_description_launch_arguments():
185186
)
186187
lc2 = LaunchContext()
187188
action2.visit(lc2)
189+
190+
191+
def test_include_python():
192+
"""Test including Python, with and without explicit PythonLaunchDescriptionSource."""
193+
this_dir = os.path.dirname(os.path.abspath(__file__))
194+
simple_launch_file_path = os.path.join(this_dir,
195+
'..',
196+
'launch_description_source',
197+
'simple.launch.py')
198+
199+
# Explicitly construct with PythonLaunchDescriptionSource
200+
plds = PythonLaunchDescriptionSource(simple_launch_file_path)
201+
action0 = IncludeLaunchDescription(plds)
202+
203+
# Construct action with path instead of PythonLaunchDescriptionSource object
204+
action1 = IncludeLaunchDescription(simple_launch_file_path)
205+
206+
# The two actions should be equivalent
207+
for action in [action0, action1]:
208+
assert 'IncludeLaunchDescription' in action.describe()
209+
assert isinstance(action.describe_sub_entities(), list)
210+
assert isinstance(action.describe_conditional_sub_entities(), list)
211+
# Result should only contain a single launch description as there are no launch arguments.
212+
assert len(action.visit(LaunchContext())) == 1
213+
assert action.get_asyncio_future() is None
214+
assert len(action.launch_arguments) == 0
215+
216+
assert action.launch_description_source.location == simple_launch_file_path

0 commit comments

Comments
 (0)