launch.substitutions package
Submodules
- launch.substitutions.anon_name module
- launch.substitutions.boolean_substitution module
- launch.substitutions.command module
- launch.substitutions.environment_variable module
- launch.substitutions.equals_substitution module
- launch.substitutions.file_content module
- launch.substitutions.find_executable module
- launch.substitutions.if_else_substitution module
- launch.substitutions.launch_configuration module
- launch.substitutions.launch_log_dir module
- launch.substitutions.local_substitution module
- launch.substitutions.not_equals_substitution module
- launch.substitutions.path_join_substitution module
- launch.substitutions.python_expression module
- launch.substitutions.substitution_failure module
- launch.substitutions.text_substitution module
- launch.substitutions.this_launch_file module
- launch.substitutions.this_launch_file_dir module
Module contents
Package for substitutions.
- class launch.substitutions.AllSubstitution[source]
Bases:
Substitution
Substitutes to the string ‘true’ if all of the input arguments evaluate to true.
If any of the arguments evaluates to false, then this substitution returns the string ‘false’.
- __init__(*args: str | Substitution | Iterable[str | Substitution]) None [source]
Create an AllSubstitution substitution.
The following string arguments evaluate to true: ‘1’, ‘true’, ‘True’, ‘on’ The following string arguments evaluate to false: ‘0’, ‘false’, ‘False’, ‘off’
- property args: List[List[Substitution]]
Getter for args.
- classmethod parse(data: Iterable[str | Substitution | Iterable[str | Substitution]])[source]
Parse AllSubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution.
- class launch.substitutions.AndSubstitution[source]
Bases:
Substitution
Substitution that returns ‘and’ of the input boolean values.
- __init__(left: str | Substitution | Iterable[str | Substitution], right: str | Substitution | Iterable[str | Substitution]) None [source]
Create an AndSubstitution substitution.
- property left: List[Substitution]
Getter for left.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse AndSubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution.
- property right: List[Substitution]
Getter for right.
- class launch.substitutions.AnonName[source]
Bases:
Substitution
Generates an anonymous id based on name.
Name itself is a unique identifier: multiple uses of anon with the same parameter name will create the same “anonymized” name
- __init__(name: str | Substitution | Iterable[str | Substitution]) None [source]
Construct an AnonName substitution.
- property name: List[Substitution]
Getter for name.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse AnonName substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by creating/getting the anonymous name.
- class launch.substitutions.AnySubstitution[source]
Bases:
Substitution
Substitutes to the string ‘true’ if at least one of the input arguments evaluates to true.
If none of the arguments evaluate to true, then this substitution returns the string ‘false’.
- __init__(*args: str | Substitution | Iterable[str | Substitution]) None [source]
Create an AnySubstitution substitution.
The following string arguments evaluate to true: ‘1’, ‘true’, ‘True’, ‘on’
- property args: List[List[Substitution]]
Getter for args.
- classmethod parse(data: Iterable[str | Substitution | Iterable[str | Substitution]])[source]
Parse AnySubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution.
- class launch.substitutions.Command[source]
Bases:
Substitution
Substitution that gets the output of a command as a string.
If the command is not found or fails a SubstitutionFailure error is raised. Behavior on stderr output is configurable, see constructor.
- __init__(command: str | Substitution | Iterable[str | Substitution], *, on_stderr: str | Substitution | Iterable[str | Substitution] = 'fail') None [source]
Construct a command substitution.
- Parameters:
command – command to be executed. The substitutions will be performed, and shlex.split will be used on the result.
on_stderr – specifies what to do when there is stderr output. Can be one of: - ‘fail’: raises SubstitutionFailere when stderr output is detected. - ‘ignore’: stderr output is ignored. - ‘warn’: The stderr output is ignored, but a warning is logged if detected. - ‘capture’: The stderr output will be captured, together with stdout. It can also be a substitution, that results in one of those four options.
- property command: List[Substitution]
Getter for command.
- property on_stderr: List[Substitution]
Getter for on_stderr.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse Command substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by running the command and capturing its output.
- class launch.substitutions.EnvironmentVariable[source]
Bases:
Substitution
Substitution that gets an environment variable value as a string.
If the environment variable is not found, it returns empty string.
Note that the environment variable is resolved based on the launch context’s environment (i.e.,
context.environment
) even though the substitution may be associated with an entity that might have a different set of environment variables.- __init__(name: str | Substitution | Iterable[str | Substitution], *, default_value: str | Substitution | Iterable[str | Substitution] | None = None) None [source]
Construct an environment variable substitution.
- Parameters:
name – name of the environment variable.
default_value – used when the environment variable doesn’t exist. If None, the substitution is not optional.
- Raises:
launch.substitutions.substitution_failure.SubstitutionFailure – If the environment variable doesn’t exist and default_value is None.
- property default_value: List[Substitution] | None
Getter for default_value.
- property name: List[Substitution]
Getter for name.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse EnviromentVariable substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by looking up the environment variable.
- class launch.substitutions.EqualsSubstitution[source]
Bases:
Substitution
Substitution that checks if two inputs are equal.
Returns ‘true’ or ‘false’ strings depending on the result.
- __init__(left: Any | Iterable[Any] | None, right: Any | Iterable[Any] | None) None [source]
Create an EqualsSubstitution substitution.
- property left: List[Substitution]
Getter for left.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse EqualsSubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution.
- property right: List[Substitution]
Getter for right.
- class launch.substitutions.FileContent[source]
Bases:
Substitution
Substitution that reads the contents of a file.
If the file is not found a SubstitutionFailure error is raised.
- __init__(path: str | Substitution | Iterable[str | Substitution]) None [source]
Create a FileContent substitution.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse FileContent substitution.
- property path: List[Substitution]
Getter for path.
- perform(context: LaunchContext) str [source]
Perform the substitution by evaluating the expression.
- class launch.substitutions.FindExecutable[source]
Bases:
Substitution
Substitution that tries to locate an executable on the PATH.
- Raise:
SubstitutionFailure when executable not found
- __init__(*, name: str | Substitution | Iterable[str | Substitution]) None [source]
Create a FindExecutable substitution.
- property name: List[Substitution]
Getter for name.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse FindExecutable substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by locating the executable on the PATH.
- class launch.substitutions.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 | Substitution | Iterable[str | Substitution], if_value: str | Substitution | Iterable[str | Substitution] = '', else_value: str | Substitution | Iterable[str | Substitution] = '') None [source]
Create a IfElseSubstitution substitution.
- property condition: List[Substitution]
Getter for condition.
- property else_value: List[Substitution]
Getter for else value.
- property if_value: List[Substitution]
Getter for if value.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse IfElseSubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by evaluating the condition.
- class launch.substitutions.LaunchConfiguration[source]
Bases:
Substitution
Substitution that can access launch configuration variables.
- __init__(variable_name: str | Substitution | Iterable[str | Substitution], *, default: Any | Iterable[Any] | None = None) None [source]
Create a LaunchConfiguration substitution.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse FindExecutable substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by retrieving the launch configuration, as a string.
If the launch configuration is not found and a default has been set, the default will be returned, as a string.
- property variable_name: List[Substitution]
Getter for variable_name.
- class launch.substitutions.LaunchLogDir[source]
Bases:
Substitution
Substitution that returns the absolute path to the current launch log directory.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse LaunchLogDir substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by returning the path to the current launch log directory.
- class launch.substitutions.LocalSubstitution[source]
Bases:
Substitution
Substitution that can access contextual local variables.
- __init__(expression: str, description: str | None = None) None [source]
Create a LocalSubstitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by retrieving the local variable.
- class launch.substitutions.NotEqualsSubstitution[source]
Bases:
EqualsSubstitution
Substitution that checks if two inputs are not equal.
Returns ‘true’ or ‘false’ strings depending on the result.
- __init__(left: Any | Iterable[Any] | None, right: Any | Iterable[Any] | None) None [source]
Create a NotEqualsSubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution.
- class launch.substitutions.NotSubstitution[source]
Bases:
Substitution
Substitution that returns ‘not’ of the input boolean value.
- __init__(value: str | Substitution | Iterable[str | Substitution]) None [source]
Create a NotSubstitution substitution.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse NotSubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution.
- property value: List[Substitution]
Getter for value.
- class launch.substitutions.OrSubstitution[source]
Bases:
Substitution
Substitution that returns ‘or’ of the input boolean values.
- __init__(left: str | Substitution | Iterable[str | Substitution], right: str | Substitution | Iterable[str | Substitution]) None [source]
Create an OrSubstitution substitution.
- property left: List[Substitution]
Getter for left.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse OrSubstitution substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution.
- property right: List[Substitution]
Getter for right.
- class launch.substitutions.PathJoinSubstitution[source]
Bases:
Substitution
Substitution that join paths, in a platform independent way.
- perform(context: LaunchContext) str [source]
Perform the substitution by retrieving the local variable.
- property substitutions: Iterable[Substitution]
Getter for variable_name.
- class launch.substitutions.PythonExpression[source]
Bases:
Substitution
Substitution that can access contextual local variables.
The expression may contain Substitutions, but must return something that can be converted to a string with str(). It also may contain math symbols and functions.
- __init__(expression: str | Substitution | Iterable[str | Substitution], python_modules: str | Substitution | Iterable[str | Substitution] = ['math']) None [source]
Create a PythonExpression substitution.
- property expression: List[Substitution]
Getter for expression.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse PythonExpression substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by evaluating the expression.
- property python_modules: List[Substitution]
Getter for python modules.
- exception launch.substitutions.SubstitutionFailure[source]
Bases:
RuntimeError
Raised when a Substitution fails.
- class launch.substitutions.TextSubstitution[source]
Bases:
Substitution
Substitution that wraps a single string text.
- perform(context: LaunchContext) str [source]
Perform the substitution by returning the string itself.
- class launch.substitutions.ThisLaunchFile[source]
Bases:
Substitution
Substitution that returns the absolute path to the current launch file.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse ThisLaunchFile substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by returning the path to the current launch file.
If there is no current launch file, i.e. if run from a script, then an error is raised.
- Raises:
SubstitutionFailure if not in a launch file
- class launch.substitutions.ThisLaunchFileDir[source]
Bases:
Substitution
Substitution that returns the absolute path to the current launch file.
- classmethod parse(data: Sequence[str | Substitution | Iterable[str | Substitution]])[source]
Parse ThisLaunchFileDir substitution.
- perform(context: LaunchContext) str [source]
Perform the substitution by returning the path to the current launch file.
If there is no current launch file, i.e. if run from a script, then an error is raised.
- Raises:
launch.substitutions.substitution_failure.SubstitutionFailure – if not in a launch file