launch_ros.utilities.namespace_utils module

Module with utility functions for handling namespaces.

launch_ros.utilities.namespace_utils.is_namespace_absolute(ns: str) bool

Return True if ns is absolute.

launch_ros.utilities.namespace_utils.is_root_namespace(ns: str) bool

Return True if ns is ‘/’.

launch_ros.utilities.namespace_utils.make_namespace_absolute(ns: OptionalText) OptionalText

Make a relative namespace absolute.

launch_ros.utilities.namespace_utils.prefix_namespace(base_ns: str | None, ns: str | None) str | None

Return ns prefixed with base_ns if ns is relative, return ns if not.

Parameters:
  • base_ns – Prefix to be added to ns.

  • ns – Namespace to be prefixed.

Returns:

None if both base_ns and ns are None, or base_ns if ns is None, or ns if base_ns is None, or ns if ns is absolute, or ns prefixed with base_ns. In all cases, trailing / are stripped from the result.

## Examples:

```python3 combined_ns = prefix_namespace(‘my_ns’, ‘original_ns’) assert combined_ns == ‘my_ns/original_ns’

combined_ns = prefix_namespace(‘/my_ns’, ‘original_ns’) assert combined_ns == ‘/my_ns/original_ns’

combined_ns = prefix_namespace(‘my_ns’, ‘/original_ns’) assert combined_ns == ‘/original_ns’

combined_ns = prefix_namespace(None, ‘original_ns’) assert combined_ns == ‘original_ns’

combined_ns = prefix_namespace(‘my_ns’, None) assert combined_ns == ‘my_ns’ ```