Skip to content

Commit 658ba9d

Browse files
[backport jazzy] Make the directory-finding substitutions into a PathSubstitution for / operator (backport #914) (#918)
Co-authored-by: Emerson Knapp <emerson.b.knapp@gmail.com>
1 parent 91c9bd5 commit 658ba9d

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

launch/launch/substitutions/launch_log_dir.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
from typing import Sequence
1818
from typing import Text
1919

20+
from .path_join_substitution import PathSubstitution
2021
from ..frontend.expose import expose_substitution
2122
from ..launch_context import LaunchContext
2223
from ..logging import launch_config as launch_logging_config
2324
from ..some_substitutions_type import SomeSubstitutionsType
24-
from ..substitution import Substitution
2525

2626

2727
@expose_substitution('launch_log_dir')
2828
@expose_substitution('log_dir')
29-
class LaunchLogDir(Substitution):
29+
class LaunchLogDir(PathSubstitution):
3030
"""Substitution that returns the absolute path to the current launch log directory."""
3131

3232
def __init__(self) -> None:
3333
"""Create a LaunchLogDir substitution."""
34-
super().__init__()
34+
super().__init__(path=self)
3535

3636
@classmethod
3737
def parse(cls, data: Sequence[SomeSubstitutionsType]):

launch/launch/substitutions/this_launch_file_dir.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
from typing import Sequence
1818
from typing import Text
1919

20+
from .path_join_substitution import PathSubstitution
2021
from .substitution_failure import SubstitutionFailure
2122
from ..frontend.expose import expose_substitution
2223
from ..launch_context import LaunchContext
2324
from ..some_substitutions_type import SomeSubstitutionsType
24-
from ..substitution import Substitution
2525

2626

2727
@expose_substitution('dirname')
28-
class ThisLaunchFileDir(Substitution):
28+
class ThisLaunchFileDir(PathSubstitution):
2929
"""Substitution that returns the absolute path to the current launch file."""
3030

3131
def __init__(self) -> None:
3232
"""Create a ThisLaunchFileDir substitution."""
33-
super().__init__()
33+
super().__init__(path=self)
3434

3535
@classmethod
3636
def parse(cls, data: Sequence[SomeSubstitutionsType]):

launch/test/launch/substitutions/test_launch_log_dir.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def test_launch_log_dir_methods():
3232
assert lld.perform(lc)
3333

3434

35+
def test_launch_log_dir_path():
36+
test_dir = LaunchLogDir() / 'subdir'
37+
lc = LaunchContext()
38+
result = test_dir.perform(lc)
39+
assert result
40+
assert result.endswith('subdir')
41+
42+
3543
def test_launch_log_dir_frontend():
3644
"""Test launch_log_dir/log_dir frontend substitutions."""
3745
for sub in ('launch_log_dir', 'log_dir'):

launch/test/launch/substitutions/test_this_launch_file_dir.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Tests for the ThisLaunchFileDir substitution class."""
1616

17+
import os
18+
1719
from launch import LaunchContext
1820
from launch.substitutions import SubstitutionFailure
1921
from launch.substitutions import ThisLaunchFileDir
@@ -35,3 +37,10 @@ def test_this_launch_file_path_methods():
3537
tlfp.perform(lc)
3638
lc.extend_locals({'current_launch_file_directory': 'foo'})
3739
assert tlfp.perform(lc) == 'foo'
40+
41+
42+
def test_this_launch_file_dir_pathing():
43+
test_file = ThisLaunchFileDir() / 'some_launch.xml'
44+
lc = LaunchContext()
45+
lc.extend_locals({'current_launch_file_directory': 'foo'})
46+
assert test_file.perform(lc) == os.path.join('foo', 'some_launch.xml')

0 commit comments

Comments
 (0)