Skip to content

Commit 148723c

Browse files
emersonknappmergify[bot]
authored andcommitted
Make the directory-finding substitutions into a PathSubstitution for / operator (#914)
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com> (cherry picked from commit 0d54476) # Conflicts: # launch/launch/substitutions/launch_log_dir.py
1 parent 94b7d99 commit 148723c

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

launch/launch/substitutions/launch_log_dir.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,28 @@
1616

1717
from typing import Sequence
1818
from typing import Text
19+
<<<<<<< HEAD
1920

21+
=======
22+
from typing import Tuple
23+
from typing import Type
24+
25+
from .path_join_substitution import PathSubstitution
26+
>>>>>>> 0d54476 (Make the directory-finding substitutions into a PathSubstitution for / operator (#914))
2027
from ..frontend.expose import expose_substitution
2128
from ..launch_context import LaunchContext
2229
from ..logging import launch_config as launch_logging_config
2330
from ..some_substitutions_type import SomeSubstitutionsType
24-
from ..substitution import Substitution
2531

2632

2733
@expose_substitution('launch_log_dir')
2834
@expose_substitution('log_dir')
29-
class LaunchLogDir(Substitution):
35+
class LaunchLogDir(PathSubstitution):
3036
"""Substitution that returns the absolute path to the current launch log directory."""
3137

3238
def __init__(self) -> None:
3339
"""Create a LaunchLogDir substitution."""
34-
super().__init__()
40+
super().__init__(path=self)
3541

3642
@classmethod
3743
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)