ament_index_python package

Submodules

Module contents

exception ament_index_python.InvalidResourceNameError

Bases: ValueError

Raised when a resource name is invalid.

exception ament_index_python.InvalidResourceTypeNameError

Bases: ValueError

Raised when a resource type name is invalid.

exception ament_index_python.PackageNotFoundError

Bases: KeyError

ament_index_python.get_package_prefix(package_name: str) str

Return the installation prefix directory of the given package.

For example, if you install the package ‘foo’ into ‘/home/user/ros2_ws/install’ and you called this function with ‘foo’ as the argument, then it will return that directory.

Parameters:

package_name (str) – name of the package to locate

Returns:

installation prefix of the package

Raises:

PackageNotFoundError if the package is not found

Raises:

ValueError if the package name is invalid

ament_index_python.get_package_share_directory(package_name: str, print_warning: bool = True) str

Return the share directory of the given package.

For example, if you install the package ‘foo’ into ‘/home/user/ros2_ws/install’ and you called this function with ‘foo’ as the argument, then it will return ‘/home/user/ros2_ws/install/share/foo’ as the package’s share directory.

Parameters:
  • package_name (str) – name of the package to locate

  • print_warning (bool) – if true, print a warning if the directory does not exist

Returns:

share directory of the package

Raises:

PackageNotFoundError if the package is not found

Raises:

ValueError if the package name is invalid

ament_index_python.get_package_share_path(package_name: str, print_warning: bool = True) Path

Return the share directory of the given package as a pathlib.Path.

For example, if you install the package ‘foo’ into ‘/home/user/ros2_ws/install’ and you called this function with ‘foo’ as the argument, then it will return a path representing ‘/home/user/ros2_ws/install/share/foo’ and then you could use it to construct the path to a shared file with get_package_share_path(‘foo’) / ‘urdf/robot.urdf’

Parameters:
  • package_name (str) – name of the package to locate

  • print_warning (bool) – if true, print a warning if the path does not exist

Returns:

share directory of the package as a pathlib.Path

Raises:

PackageNotFoundError if the package is not found

ament_index_python.get_packages_with_prefixes() Dict[str, str]

Return a dict of package names to the prefixes in which they are found.

Returns:

dict of package names to their prefixes

Return type:

dict

ament_index_python.get_resource(resource_type: str, resource_name: str) Tuple[str, str]

Get the content of a specific resource and its prefix path.

Parameters:
  • resource_type (str) – the type of the resource

  • resource_names – the name of the resource

Returns:

a tuple of the content (bytes) of the resource and its prefix path

Raises:

EnvironmentError

Raises:

OSError

Raises:

LookupError

Raises:

InvalidResourceTypeNameError

Raises:

InvalidResourceNameError

ament_index_python.get_resource_types() set[str]

Get the resource types.

Returns:

set of resource types within the search paths

Raises:

EnvironmentError

ament_index_python.get_resources(resource_type: str) Dict[str, str]

Get the resource names of all resources of the specified type.

Parameters:

resource_type (str) – the type of the resource

Returns:

dict of resource names to the prefix path they are in

Raises:

EnvironmentError

Raises:

InvalidResourceTypeNameError

ament_index_python.get_search_paths() List[str]
ament_index_python.has_resource(resource_type: str, resource_name: str) str | Literal[False]

Check if a specific resource exists.

Parameters:
  • resource_type (str) – the type of the resource

  • resource_names – the name of the resource

Returns:

The prefix path if the resource exists, False otherwise

Raises:

EnvironmentError

Raises:

InvalidResourceTypeNameError

Raises:

InvalidResourceNameError