launch.substitutions.if_else_substitution module

Module for the IfElseSubstitution substitution.

class launch.substitutions.if_else_substitution.IfElseSubstitution[source]

Bases: Substitution

Substitution that conditionally returns one of two substitutions.

Depending on whether the condition substitution evaluates to true, either it returns the if_value substitution or the else_value substitution.

Example with a boolean launch configuration:

>>> from launch.substitutions import LaunchConfiguration
>>> subst = IfElseSubstitution(
...     LaunchConfiguration("arg"),
...     if_value="arg_evaluated_to_true",
...     else_value="arg_evaluated_to_false")

Combine with boolean substitutions to create more complex conditions. Example with multiple boolean launch configurations:

>>> from launch.substitutions import AllSubstitution
>>> from launch.substitutions import EqualsSubstitution
>>> from launch.substitutions import LaunchConfiguration
>>> from launch.substitutions import NotSubstitution
>>> subst = IfElseSubstitution(
...     AllSubstitution(EqualsSubstitution(LaunchConfiguration("arg1"),
...                                        LaunchConfiguration("arg2")),
...                     NotSubstitution(LaunchConfiguration("arg3"))),
...     if_value="all_args_evaluated_to_true",
...     else_value="at_least_one_arg_evaluated_to_false")
__init__(condition: str | Path | Substitution | Iterable[str | Path | Substitution], if_value: str | Path | Substitution | Iterable[str | Path | Substitution] = '', else_value: str | Path | Substitution | Iterable[str | Path | Substitution] = '') None[source]

Create a IfElseSubstitution substitution.

property condition: List[Substitution]

Getter for condition.

describe() str[source]

Return a description of this substitution as a string.

property else_value: List[Substitution]

Getter for else value.

property if_value: List[Substitution]

Getter for if value.

classmethod parse(data: Sequence[str | Path | Substitution | Iterable[str | Path | Substitution]])[source]

Parse IfElseSubstitution substitution.

perform(context: LaunchContext) str[source]

Perform the substitution by evaluating the condition.