launch.substitutions.path_join_substitution module

Module for the PathJoinSubstitution substitution.

class launch.substitutions.path_join_substitution.PathJoinSubstitution[source]

Bases: Substitution

Substitution that join paths, in a platform independent way.

This takes in a list of path components as substitutions. The substitutions for each path component are performed and concatenated, and then all path components are joined.

For example:

PathJoinSubstitution([
    EnvironmentVariable('SOME_DIR'),
    'cfg',
    ['config_', LaunchConfiguration('map'), '.yml']
])

Or:

cfg_dir = PathJoinSubstitution([EnvironmentVariable('SOME_DIR'), 'cfg'])
cfg_file = cfg_dir / ['config_', LaunchConfiguration('map'), '.yml']

If the SOME_DIR environment variable was set to /home/user/dir and the map launch configuration was set to my_map, this would result in a path equal equivalent to (depending on the platform):

'/home/user/dir/cfg/config_my_map.yml'
__init__(substitutions: Iterable[str | Path | Substitution | Iterable[str | Path | Substitution]]) None[source]

Create a PathJoinSubstitution.

Parameters:

substitutions – the list of path component substitutions to join

perform(context: LaunchContext) str[source]

Perform the substitutions and join into a path.

property substitutions: List[List[Substitution]]

Getter for substitutions.

class launch.substitutions.path_join_substitution.PathSubstitution[source]

Bases: PathJoinSubstitution

Thin wrapper on PathJoinSubstitution for more pathlib.Path-like construction.

PathSubstitution(LaunchConfiguration('base_dir')) / 'sub_dir' / 'file_name'

Which, for base_dir:=/my_dir, results in (depending on the platform):

/my_dir/sub_dir/file_name
__init__(path: str | Path | Substitution | Iterable[str | Path | Substitution])[source]

Create a PathSubstitution.

Parameters:

path – May be a single text or Substitution element,

or an Iterable of them which are then joined