Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup(
name='rosdep',
version=__version__, # noqa:F821
packages=['rosdep2', 'rosdep2.platforms'],
packages=['rosdep2', 'rosdep2.ament_packages', 'rosdep2.platforms'],
package_dir={'': 'src'},
install_requires=['catkin_pkg >= 0.4.0', 'rospkg >= 1.1.8', 'rosdistro >= 0.7.0', 'PyYAML >= 3.1'],
test_suite='nose.collector',
Expand Down
5 changes: 5 additions & 0 deletions src/rosdep2/ament_packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code within is folder is essentially copied directly from the `ament_package` repo, or more specificity the `ament_index_python` package. See original source here:

https://github.com/ament/ament_index/tree/86f5a6712690830fe3e19752f70cfcdb00a3d223/ament_index_python/ament_index_python

TODO: reconcile duplicate code via shared codebase
27 changes: 27 additions & 0 deletions src/rosdep2/ament_packages/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2015 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.

from .constants import AMENT_PREFIX_PATH_ENV_VAR
from .constants import RESOURCE_INDEX_SUBFOLDER
from .packages import get_packages_with_prefixes
from .resources import get_resources
from .search_paths import get_search_paths

__all__ = [
'get_packages_with_prefixes',
'get_resources',
'get_search_paths',
'AMENT_PREFIX_PATH_ENV_VAR',
'RESOURCE_INDEX_SUBFOLDER',
]
17 changes: 17 additions & 0 deletions src/rosdep2/ament_packages/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2015 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.


RESOURCE_INDEX_SUBFOLDER = 'share/ament_index/resource_index'
AMENT_PREFIX_PATH_ENV_VAR = 'AMENT_PREFIX_PATH'
27 changes: 27 additions & 0 deletions src/rosdep2/ament_packages/packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

import os

from .resources import get_resources


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')
43 changes: 43 additions & 0 deletions src/rosdep2/ament_packages/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2015 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.

import os

from .constants import RESOURCE_INDEX_SUBFOLDER

from .search_paths import get_search_paths


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`
"""
assert resource_type, 'The resource type must not be empty'
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
33 changes: 33 additions & 0 deletions src/rosdep2/ament_packages/search_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015 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.

import os

from .constants import AMENT_PREFIX_PATH_ENV_VAR


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)]
20 changes: 18 additions & 2 deletions src/rosdep2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
DEFAULT_SOURCES_LIST_URL
from .rosdistrohelper import PreRep137Warning

from .ament_packages import AMENT_PREFIX_PATH_ENV_VAR
from .ament_packages import get_packages_with_prefixes

from .catkin_packages import find_catkin_packages_in
from .catkin_packages import set_workspace_packages
from .catkin_packages import get_workspace_packages
Expand Down Expand Up @@ -294,8 +297,8 @@ def _rosdep_main(args):
dest='ignore_src', default=False, action='store_true',
help="Affects the 'check', 'install', and 'keys' verbs. "
'If specified then rosdep will ignore keys that '
'are found to be catkin packages anywhere in the '
'ROS_PACKAGE_PATH or in any of the directories '
'are found to be catkin or ament packages anywhere in the '
'ROS_PACKAGE_PATH, AMENT_PREFIX_PATH or in any of the directories '
'given by the --from-paths option.')
parser.add_option('--skip-keys',
dest='skip_keys', action='append', default=[],
Expand Down Expand Up @@ -476,6 +479,19 @@ def _package_args_handler(command, parser, options, args):
print('Skipping non-existent path ' + path)
set_workspace_packages(ws_pkgs)

# Lookup package names from ament index.
if AMENT_PREFIX_PATH_ENV_VAR in os.environ:
if options.verbose:
print(
'Searching ' + AMENT_PREFIX_PATH_ENV_VAR + ' for '
'sources: ' + str(os.environ[AMENT_PREFIX_PATH_ENV_VAR].split(':')))
ws_pkgs = get_workspace_packages()
pkgs = get_packages_with_prefixes().keys()
ws_pkgs.extend(pkgs)
# Make packages list unique
ws_pkgs = list(set(ws_pkgs))
set_workspace_packages(ws_pkgs)
Comment thread
wjwwood marked this conversation as resolved.

lookup = _get_default_RosdepLookup(options)

# Handle the --skip-keys option by pretending that they are packages in the catkin workspace
Expand Down
5 changes: 5 additions & 0 deletions test/test_rosdep_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from mock import DEFAULT

from rosdep2 import main
from rosdep2.ament_packages import AMENT_PREFIX_PATH_ENV_VAR
from rosdep2.main import rosdep_main
from rosdep2.main import setup_proxy_opener

Expand Down Expand Up @@ -91,15 +92,19 @@ def setUp(self):
del os.environ['ROSDEP_DEBUG']
self.old_rr = rospkg.get_ros_root()
self.old_rpp = rospkg.get_ros_package_path()
self.old_app = os.getenv(AMENT_PREFIX_PATH_ENV_VAR, None)
if 'ROS_ROOT' in os.environ:
del os.environ['ROS_ROOT']
os.environ['ROS_PACKAGE_PATH'] = os.path.join(get_test_tree_dir())
os.environ[AMENT_PREFIX_PATH_ENV_VAR] = os.path.join(get_test_tree_dir(), 'ament')

def tearDown(self):
if self.old_rr is not None:
os.environ['ROS_ROOT'] = self.old_rr
if self.old_rpp is not None:
os.environ['ROS_PACKAGE_PATH'] = self.old_rpp
if self.old_app is not None:
os.environ[AMENT_PREFIX_PATH_ENV_VAR] = self.old_app

def test_bad_commands(self):
sources_cache = get_cache_dir()
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions test/tree/catkin/fake_catkin_package/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<package>
<name>fake_catkin_package</name>
<version>0.0.0</version>
<description>
This is a simple package
</description>
<maintainer email="nobody@example.org">Nobody</maintainer>
<license>BSD</license>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>bar</build_depend>
<build_depend>foo</build_depend>
<build_depend>metapackage_with_deps</build_depend>
</package>