launch.frontend package

Submodules

Module contents

Package for launch markup.

class launch.frontend.Entity[source]

Bases: object

Single item in the intermediate front_end representation.

assert_entity_completely_parsed()[source]

Assert that all attributes and children of the entity were parsed.

This function is automatically called after the parse(entity, parser) function completed.

property children: List[Entity]

Get the Entity’s children.

get_attr(name: str, *, data_type: Type[TargetType], optional: bool, can_be_str: bool = True) TargetType | None[source]
get_attr(name: str, *, data_type: Type[TargetType], can_be_str: bool = True) TargetType
get_attr(name: str, *, optional: bool, can_be_str: bool = True) str | None
get_attr(name: str, *, can_be_str: bool = True) str

Access an attribute of the entity.

By default, it will try to return it as an string. data_type is the expected type of the attribute. Type coercion or type checking is applied depending on the particular frontend.

See launch.utilities.AllowedTypesTuple to see what types are allowed.

data_type = None will result in yaml parsing of the attribute value as a string.

List[Entity] allows accessing a list of subentities with an specific name.

Check the documentation of each specific frontend implementation to see how a list of attributes or List[Entity] look like.

If optional is True and the attribute cannot be found, None will be returned instead of raising AttributeError.

Parameters:
  • name – name of the attribute

  • data_type – type of the attribute to be read. Defaults to ‘str’

  • optional – when True, it doesn’t raise an error when the attribute is not found. It returns None instead. Defaults to False

Raises:
  • AttributeError – Attribute not found. Only possible if optional is False

  • TypeError – Attribute found but it is not of the correct type. Only happens in frontend implementations that do type checking

  • ValueError – Attribute found but can’t be coerced to one of the specified types. Only happens in frontend implementations that do type coercion.

property parent: Entity | None

Get Entity parent.

property type_name: str

Get Entity type.

exception launch.frontend.InvalidFrontendLaunchFileError[source]

Bases: InvalidLaunchFileError

Exception raised when the given frontend launch file is not valid.

class launch.frontend.Parser[source]

Bases: object

Abstract class for parsing launch actions, substitutions and descriptions.

Implementations of the parser class, should override the load method. They could also override the parse_substitution and/or get_file_extensions methods, or not. load_launch_extensions, parse_action, parse_description, get_available_extensions, may_parse, is_filename_valid, get_parsers_from_filename and get_file_extensions_from_parsers are not supposed to be overridden.

escape_characters(value: str) str[source]

Escape characters in strings.

extensions_loaded = False
frontend_parsers = None
classmethod get_available_extensions() List[str][source]

Return the registered extensions.

classmethod get_file_extensions() Set[str][source]

Return the set of file extensions known to this parser.

classmethod get_file_extensions_from_parsers() Set[Type[Parser]][source]

Return a set of file extensions known to the parser implementations.

classmethod get_parser_from_extension(extension: str) Type[Parser] | None[source]

Return an entity loaded with a markup file.

classmethod get_parsers_from_filename(filename: str) List[Type[Parser]][source]

Return a list of parsers which entity loaded with a markup file.

classmethod is_extension_valid(extension: str) bool[source]

Return an entity loaded with a markup file.

classmethod is_filename_valid(filename: str) bool[source]

Return True if the filename is valid for any parser.

classmethod load(file: FilePath | TextIO) Tuple[Entity, Parser][source]

Parse an Entity from a markup language-based launch file.

Parsers are exposed and provided by available frontend implementations. To choose the right parser, it’ll first attempt to infer the launch description format based on the filename extension, if any. If format inference fails, it’ll try all available parsers one after the other.

classmethod load_launch_extensions()[source]

Load launch extensions, in order to get all the exposed substitutions and actions.

classmethod load_parser_implementations()[source]

Load all the available frontend entities.

classmethod may_parse(filename: str) bool[source]

Return True if the filename is valid for this parser.

parse_action(entity: Entity) Action[source]

Parse an action, using its registered parsing method.

parse_description(entity: Entity) LaunchDescription[source]

Parse a launch description.

parse_if_substitutions(value: str | Substitution | Iterable[str | Substitution] | int | float | bool | Sequence[int | str] | Sequence[float | str] | Sequence[bool | str] | Sequence[str]) List[Substitution] | int | float | bool | str | List[int | List[Substitution]] | List[float | List[Substitution]] | List[bool | List[Substitution]] | List[str | List[Substitution]][source]

See launch.frontend.parser.parse_if_substitutions().

parse_substitution(value: str) List[Substitution][source]

Parse a substitution.

launch.frontend.expose_action(name: str)[source]

Return a decorator for exposing an action.

Read __expose_impl documentation.

launch.frontend.expose_substitution(name: str)[source]

Return a decorator for exposing a substitution.

Read __expose_impl documentation.