# Path: ament_index_python/ament_index_python/resources.py
# def get_resource(resource_type, resource_name):
#     """
#     Get the content of a specific resource and its prefix path.
# 
#     :param resource_type: the type of the resource
#     :type resource_type: str
#     :param resource_names: the name of the resource
#     :type resource_name: str
#     :returns: a tuple of the content (bytes) of the resource and its prefix path
#     :raises: :exc:`EnvironmentError`
#     :raises: :exc:`OSError`
#     :raises: :exc:`LookupError`
#     :raises: :exc:`InvalidResourceTypeNameError`
#     :raises: :exc:`InvalidResourceNameError`
#     """
#     assert resource_type, 'The resource type must not be empty'
#     assert resource_name, 'The resource name must not be empty'
#     if _name_is_invalid(resource_type):
#         raise InvalidResourceTypeNameError(
#             "Resource type '%s' is invalid" % resource_type)
#     if _name_is_invalid(resource_name):
#         raise InvalidResourceNameError(
#             "Resource name '%s' is invalid" % resource_name)
#     for path in get_search_paths():
#         resource_path = os.path.join(path, RESOURCE_INDEX_SUBFOLDER, resource_type, resource_name)
#         if os.path.isfile(resource_path):
#             try:
#                 with open(resource_path, 'r') as h:
#                     content = h.read()
#             except OSError as e:
#                 raise OSError(
#                     "Could not open the resource '%s' of type '%s':\n%s"
#                     % (resource_name, resource_type, e))
#             return content, path
#     raise LookupError(
#         "Could not find the resource '%s' of type '%s'" % (resource_name, resource_type))
# 
# Path: ament_index_python/ament_index_python/resources.py
# def get_resources(resource_type):
#     """
#     Get the resource names of all resources of the specified type.
# 
#     :param resource_type: the type of the resource
#     :type resource_type: str
#     :returns: dict of resource names to the prefix path they are in
#     :raises: :exc:`EnvironmentError`
#     :raises: :exc:`InvalidResourceTypeNameError`
#     """
#     assert resource_type, 'The resource type must not be empty'
#     if _name_is_invalid(resource_type):
#         raise InvalidResourceTypeNameError(
#             "Resource type '%s' is invalid" % resource_type)
#     resources = {}
#     for path in get_search_paths():
#         resource_path = os.path.join(path, RESOURCE_INDEX_SUBFOLDER, resource_type)
#         if os.path.isdir(resource_path):
#             for resource in os.listdir(resource_path):
#                 # Ignore subdirectories, and anything starting with a dot
#                 if os.path.isdir(os.path.join(resource_path, resource)) \
#                         or resource.startswith('.'):
#                     continue
#                 if resource not in resources:
#                     resources[resource] = path
#     return resources
# 
# Path: ament_index_python/ament_index_python/search_paths.py
# def get_search_paths():
#     """
#     Get the paths from the environment variable '{AMENT_PREFIX_PATH_ENV_VAR}'.
# 
#     :returns: list of paths
#     :raises: :exc:`EnvironmentError`
#     """.format(AMENT_PREFIX_PATH_ENV_VAR=AMENT_PREFIX_PATH_ENV_VAR)
#     ament_prefix_path = os.environ.get(AMENT_PREFIX_PATH_ENV_VAR)
#     if not ament_prefix_path:
#         raise EnvironmentError(
#             "Environment variable '{}' is not set or empty".format(AMENT_PREFIX_PATH_ENV_VAR))
# 
#     paths = ament_prefix_path.split(os.pathsep)
#     return [p for p in paths if p and os.path.exists(p)]


import os
import pathlib
import re
import warnings
from .resources import get_resource
from .resources import get_resources
from .search_paths import get_search_paths
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




class PackageNotFoundError(KeyError):
    pass


def get_packages_with_prefixes():
    """
    Return a dict of package names to the prefixes in which they are found.

    :returns: dict of package names to their prefixes
    :rtype: dict
    """

# Path: ament_index_python/ament_index_python/resources.py
# def get_resource(resource_type, resource_name):
#     """
#     Get the content of a specific resource and its prefix path.
# 
#     :param resource_type: the type of the resource
#     :type resource_type: str
#     :param resource_names: the name of the resource
#     :type resource_name: str
#     :returns: a tuple of the content (bytes) of the resource and its prefix path
#     :raises: :exc:`EnvironmentError`
#     :raises: :exc:`OSError`
#     :raises: :exc:`LookupError`
#     :raises: :exc:`InvalidResourceTypeNameError`
#     :raises: :exc:`InvalidResourceNameError`
#     """
#     assert resource_type, 'The resource type must not be empty'
#     assert resource_name, 'The resource name must not be empty'
#     if _name_is_invalid(resource_type):
#         raise InvalidResourceTypeNameError(
#             "Resource type '%s' is invalid" % resource_type)
#     if _name_is_invalid(resource_name):
#         raise InvalidResourceNameError(
#             "Resource name '%s' is invalid" % resource_name)
#     for path in get_search_paths():
#         resource_path = os.path.join(path, RESOURCE_INDEX_SUBFOLDER, resource_type, resource_name)
#         if os.path.isfile(resource_path):
#             try:
#                 with open(resource_path, 'r') as h:
#                     content = h.read()
#             except OSError as e:
#                 raise OSError(
#                     "Could not open the resource '%s' of type '%s':\n%s"
#                     % (resource_name, resource_type, e))
#             return content, path
#     raise LookupError(
#         "Could not find the resource '%s' of type '%s'" % (resource_name, resource_type))
# 
# Path: ament_index_python/ament_index_python/resources.py
# def get_resources(resource_type):
#     """
#     Get the resource names of all resources of the specified type.
# 
#     :param resource_type: the type of the resource
#     :type resource_type: str
#     :returns: dict of resource names to the prefix path they are in
#     :raises: :exc:`EnvironmentError`
#     :raises: :exc:`InvalidResourceTypeNameError`
#     """
#     assert resource_type, 'The resource type must not be empty'
#     if _name_is_invalid(resource_type):
#         raise InvalidResourceTypeNameError(
#             "Resource type '%s' is invalid" % resource_type)
#     resources = {}
#     for path in get_search_paths():
#         resource_path = os.path.join(path, RESOURCE_INDEX_SUBFOLDER, resource_type)
#         if os.path.isdir(resource_path):
#             for resource in os.listdir(resource_path):
#                 # Ignore subdirectories, and anything starting with a dot
#                 if os.path.isdir(os.path.join(resource_path, resource)) \
#                         or resource.startswith('.'):
#                     continue
#                 if resource not in resources:
#                     resources[resource] = path
#     return resources
# 
# Path: ament_index_python/ament_index_python/search_paths.py
# def get_search_paths():
#     """
#     Get the paths from the environment variable '{AMENT_PREFIX_PATH_ENV_VAR}'.
# 
#     :returns: list of paths
#     :raises: :exc:`EnvironmentError`
#     """.format(AMENT_PREFIX_PATH_ENV_VAR=AMENT_PREFIX_PATH_ENV_VAR)
#     ament_prefix_path = os.environ.get(AMENT_PREFIX_PATH_ENV_VAR)
#     if not ament_prefix_path:
#         raise EnvironmentError(
#             "Environment variable '{}' is not set or empty".format(AMENT_PREFIX_PATH_ENV_VAR))
# 
#     paths = ament_prefix_path.split(os.pathsep)
#     return [p for p in paths if p and os.path.exists(p)]


# Path: ament_index_python/ament_index_python/packages.py
import os
import pathlib
import re
import warnings
from .resources import get_resource
from .resources import get_resources
from .search_paths import get_search_paths

# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




class PackageNotFoundError(KeyError):
    pass


def get_packages_with_prefixes():
    """
    Return a dict of package names to the prefixes in which they are found.

    :returns: dict of package names to their prefixes
    :rtype: dict
    """

    return get_resources('packages')