From 02394409d04227b380c8668326c678272914a035 Mon Sep 17 00:00:00 2001 From: Kyle Fazzari Date: Thu, 6 Jun 2019 13:08:53 -0700 Subject: [PATCH] keys: add support for --ignore-src Currently `--ignore-src` is only supported by the `check` and `install` verbs. Add support in the `keys` verb as well, displaying dependencies that are not already satisfied by other packages in the workspace. Resolve #685 Signed-off-by: Kyle Fazzari --- src/rosdep2/main.py | 19 ++++++++++--------- test/test_rosdep_main.py | 5 +++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/rosdep2/main.py b/src/rosdep2/main.py index 585ad8b1e5..50a0bb4b63 100644 --- a/src/rosdep2/main.py +++ b/src/rosdep2/main.py @@ -61,7 +61,7 @@ from .core import RosdepInternalError, InstallFailed, UnsupportedOs, InvalidData, CachePermissionError, DownloadFailure from .installers import normalize_uninstalled_to_list from .installers import RosdepInstaller -from .lookup import RosdepLookup, ResolutionError +from .lookup import RosdepLookup, ResolutionError, prune_catkin_packages from .rospkg_loader import DEFAULT_VIEW_KEY from .sources_list import update_sources_list, get_sources_cache_dir,\ download_default_sources_list, SourcesListLoader, CACHE_INDEX,\ @@ -292,10 +292,10 @@ def _rosdep_main(args): action='store_false', help="Do not consider implicit/recursive dependencies. Only valid with 'keys', 'check', and 'install' commands.") parser.add_option('--ignore-packages-from-source', '--ignore-src', '-i', dest='ignore_src', default=False, action='store_true', - help="Affects the 'check' and 'install' verbs. If " - 'specified then rosdep will not install keys ' - 'that are found to be catkin packages anywhere in ' - 'the ROS_PACKAGE_PATH or in any of the directories ' + 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 ' 'given by the --from-paths option.') parser.add_option('--skip-keys', dest='skip_keys', action='append', default=[], @@ -462,7 +462,7 @@ def _package_args_handler(command, parser, options, args): raise rospkg.ResourceNotFound(not_found[0], rospack.get_ros_paths()) # Handle the --ignore-src option - if command in ['install', 'check'] and options.ignore_src: + if command in ['install', 'check', 'keys'] and options.ignore_src: if options.verbose: print('Searching ROS_PACKAGE_PATH for ' 'sources: ' + str(os.environ['ROS_PACKAGE_PATH'].split(':'))) @@ -617,16 +617,17 @@ def update_error_handler(data_source, exc): def command_keys(lookup, packages, options): lookup = _get_default_RosdepLookup(options) rosdep_keys = get_keys(lookup, packages, options.recursive) + prune_catkin_packages(rosdep_keys, options.verbose) _print_lookup_errors(lookup) print('\n'.join(rosdep_keys)) def get_keys(lookup, packages, recursive): - rosdep_keys = [] + rosdep_keys = set() # using a set to ensure uniqueness for package_name in packages: deps = lookup.get_rosdeps(package_name, implicit=recursive) - rosdep_keys.extend(deps) - return set(rosdep_keys) + rosdep_keys.update(deps) + return list(rosdep_keys) def command_check(lookup, packages, options): diff --git a/test/test_rosdep_main.py b/test/test_rosdep_main.py index 8c6a59578c..cec0859ff5 100644 --- a/test/test_rosdep_main.py +++ b/test/test_rosdep_main.py @@ -245,6 +245,7 @@ def test_what_needs(self): def test_keys(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] + catkin_tree = get_test_catkin_tree_dir() try: with fakeout() as b: @@ -256,6 +257,10 @@ def test_keys(self): rosdep_main(['keys', 'rospack_fake', '--os', 'ubuntu:lucid', '--verbose'] + cmd_extras) stdout, stderr = b assert stdout.getvalue().strip() == 'testtinyxml', stdout.getvalue() + with fakeout() as b: + rosdep_main(['keys', 'another_catkin_package'] + cmd_extras + ['-i']) + stdout, stderr = b + assert stdout.getvalue().strip() == 'catkin', stdout.getvalue() except SystemExit: assert False, 'system exit occurred' try: