From 8e1e84c848c3872b70f797d94ea515daa815f14f Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Thu, 16 Jun 2022 10:33:16 +0900 Subject: [PATCH] resolve(self, rosdep,rosdep_arg_dict) move rosdep argument after rosdep_args_dict adn add default value for backward compatibility --- src/rosdep2/catkin_support.py | 2 +- src/rosdep2/installers.py | 7 +++--- src/rosdep2/lookup.py | 2 +- src/rosdep2/platforms/osx.py | 6 ++++-- src/rosdep2/platforms/pip.py | 4 +++- src/rosdep2/platforms/source.py | 6 ++++-- test/test_rosdep_installers.py | 20 ++++++++--------- test/test_rosdep_pip.py | 38 ++++++++++++++++----------------- test/test_rosdep_source.py | 9 ++++---- 9 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/rosdep2/catkin_support.py b/src/rosdep2/catkin_support.py index cce58301e..4fb3fb3b8 100644 --- a/src/rosdep2/catkin_support.py +++ b/src/rosdep2/catkin_support.py @@ -90,7 +90,7 @@ def resolve_for_os(rosdep_key, view, installer, os_name, os_version): default_os_installer = ctx.get_default_os_installer_key(os_name) inst_key, rule = d.get_rule_for_platform(os_name, os_version, os_installers, default_os_installer) assert inst_key in os_installers - return installer.resolve({}, rule) + return installer.resolve(rule) def update_rosdep(): diff --git a/src/rosdep2/installers.py b/src/rosdep2/installers.py index a1d2b6b09..f6ed1b090 100644 --- a/src/rosdep2/installers.py +++ b/src/rosdep2/installers.py @@ -34,6 +34,7 @@ import traceback from rospkg.os_detect import OsDetect +from catkin_pkg.package import Dependency from .core import rd_debug, RosdepInternalError, InstallFailed, print_bold, InvalidData @@ -278,10 +279,10 @@ def get_depends(self, rosdep_args): """ return [] # Default return empty list - def resolve(self, rosdep, rosdep_args_dict): + def resolve(self, rosdep_args_dict, rosdep=Dependency('null')): """ - :param rosdep: rosdep key (catkin_pkg.package.Dependency object) to resolve :param rosdep_args_dict: argument dictionary to the rosdep rule for this package manager + :param rosdep: rosdep key (catkin_pkg.package.Dependency object) to resolve :returns: [resolutions]. resolved objects should be printable to a user, but are otherwise opaque. """ raise NotImplementedError('Base class resolve', rosdep_args_dict) @@ -337,7 +338,7 @@ def elevate_priv(self, cmd): """ return (self.sudo_command.split() if self.as_root else []) + cmd - def resolve(self, rosdep, rosdep_args): + def resolve(self, rosdep_args, rosdep=Dependency('null')): """ See :meth:`Installer.resolve()` """ diff --git a/src/rosdep2/lookup.py b/src/rosdep2/lookup.py index 01935daec..6c2ff6de6 100644 --- a/src/rosdep2/lookup.py +++ b/src/rosdep2/lookup.py @@ -498,7 +498,7 @@ def resolve(self, rosdep, resource_name, installer_context): installer = installer_context.get_installer(installer_key) except KeyError: raise ResolutionError(rosdep_key, definition.data, os_name, os_version, 'Unsupported installer [%s]' % (installer_key)) - resolution = installer.resolve(rosdep, rosdep_args_dict) + resolution = installer.resolve(rosdep_args_dict, rosdep) dependencies = installer.get_depends(rosdep_args_dict) # cache value diff --git a/src/rosdep2/platforms/osx.py b/src/rosdep2/platforms/osx.py index 21a8488fd..b93dd8bfd 100644 --- a/src/rosdep2/platforms/osx.py +++ b/src/rosdep2/platforms/osx.py @@ -34,6 +34,8 @@ from rospkg.os_detect import OS_OSX, OsDetect +from catkin_pkg.package import Dependency + from ..core import InstallFailed, RosdepInternalError, InvalidData from .pip import PIP_INSTALLER from .source import SOURCE_INSTALLER @@ -281,7 +283,7 @@ def get_version_strings(self): except OSError: return ['Homebrew not-found'] - def resolve(self, rosdep, rosdep_args): + def resolve(self, rosdep_args, rosdep=Dependency('null')): """ See :meth:`Installer.resolve()` """ @@ -318,7 +320,7 @@ def handle_options(options): return options - packages = super(HomebrewInstaller, self).resolve(rosdep, rosdep_args) + packages = super(HomebrewInstaller, self).resolve(rosdep_args, rosdep) resolution = [] if packages: options = [] diff --git a/src/rosdep2/platforms/pip.py b/src/rosdep2/platforms/pip.py index 560ff4f5b..04cacb466 100644 --- a/src/rosdep2/platforms/pip.py +++ b/src/rosdep2/platforms/pip.py @@ -34,6 +34,8 @@ import subprocess import sys +from catkin_pkg.package import Dependency + from ..core import InstallFailed, InvalidData from ..installers import PackageManagerInstaller from ..shell_utils import read_stdout @@ -132,7 +134,7 @@ class PipInstaller(PackageManagerInstaller): def __init__(self): super(PipInstaller, self).__init__(pip_detect, supports_depends=True) - def resolve(self, rosdep, rosdep_args): + def resolve(self, rosdep_args, rosdep=Dependency('null')): """ See :meth:`Installer.resolve()` """ diff --git a/src/rosdep2/platforms/source.py b/src/rosdep2/platforms/source.py index afba83b4f..fc4f45cb7 100644 --- a/src/rosdep2/platforms/source.py +++ b/src/rosdep2/platforms/source.py @@ -42,6 +42,8 @@ import yaml +from catkin_pkg.package import Dependency + from ..core import rd_debug, InvalidData from ..installers import PackageManagerInstaller, InstallFailed from ..shell_utils import create_tempfile_from_string_and_execute @@ -201,7 +203,7 @@ def __init__(self): super(SourceInstaller, self).__init__(source_detect, supports_depends=True) self._rdmanifest_cache = {} - def resolve(self, rosdep, rosdep_args): + def resolve(self, rosdep_args, rosdep=Dependency('null')): """ :raises: :exc:`InvalidData` If format invalid or unable to retrieve rdmanifests. @@ -246,7 +248,7 @@ def get_install_command(self, resolved, interactive=True, reinstall=False, quiet def get_depends(self, rosdep_args): deps = rosdep_args.get('depends', []) - for r in self.resolve({}, rosdep_args): + for r in self.resolve(rosdep_args): deps.extend(r.dependencies) return deps diff --git a/test/test_rosdep_installers.py b/test/test_rosdep_installers.py index db1c9287c..0a29f7c13 100644 --- a/test/test_rosdep_installers.py +++ b/test/test_rosdep_installers.py @@ -307,7 +307,7 @@ def test_Installer_tripwire(): except NotImplementedError: pass try: - Installer().resolve(Dependency('null'), {}) + Installer().resolve({}) assert False except NotImplementedError: pass @@ -347,22 +347,22 @@ def test_PackageManagerInstaller_resolve(): from rosdep2.installers import PackageManagerInstaller installer = PackageManagerInstaller(detect_fn_all) - assert ['baz'] == installer.resolve(Dependency('baz'), dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), dict(packages=['baz', 'bar'])) + assert ['baz'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz']), Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve(dict(packages=['baz', 'bar']), Dependency('baz')) # test string logic - assert ['baz'] == installer.resolve(Dependency('baz'), dict(depends=['foo', 'bar'], packages='baz')) - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), dict(packages='baz bar')) - assert ['baz'] == installer.resolve(Dependency('baz'), 'baz') - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), 'baz bar') + assert ['baz'] == installer.resolve(dict(depends=['foo', 'bar'], packages='baz'), Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve(dict(packages='baz bar'), Dependency('baz')) + assert ['baz'] == installer.resolve('baz', Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve('baz bar', Dependency('baz')) # test list logic - assert ['baz'] == installer.resolve(Dependency('baz'), ['baz']) - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), ['baz', 'bar']) + assert ['baz'] == installer.resolve(['baz'], Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve(['baz', 'bar'], Dependency('baz')) # test invalid data try: - installer.resolve(Dependency('baz'), 0) + installer.resolve(0, Dependency('baz')) assert False, 'should have raised' except InvalidData: pass diff --git a/test/test_rosdep_pip.py b/test/test_rosdep_pip.py index f95537fd7..7d6d770a7 100644 --- a/test/test_rosdep_pip.py +++ b/test/test_rosdep_pip.py @@ -73,37 +73,37 @@ def test_PackageManagerInstaller_resolve(): from catkin_pkg.package import Dependency installer = PipInstaller() - assert ['baz'] == installer.resolve(Dependency('baz'), dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), dict(packages=['baz', 'bar'])) + assert ['baz'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz']), Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve(dict(packages=['baz', 'bar']), Dependency('baz')) # test string logic - assert ['baz'] == installer.resolve(Dependency('baz'), dict(depends=['foo', 'bar'], packages='baz')) - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), dict(packages='baz bar')) - assert ['baz'] == installer.resolve(Dependency('baz'), 'baz') - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), 'baz bar') + assert ['baz'] == installer.resolve(dict(depends=['foo', 'bar'], packages='baz'), Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve(dict(packages='baz bar'), Dependency('baz')) + assert ['baz'] == installer.resolve('baz', Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve('baz bar', Dependency('baz')) # test list logic - assert ['baz'] == installer.resolve(Dependency('baz'), ['baz']) - assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), ['baz', 'bar']) + assert ['baz'] == installer.resolve(['baz'], Dependency('baz')) + assert ['baz', 'bar'] == installer.resolve(['baz', 'bar'], Dependency('baz')) # version_eq - assert ['baz==1.0'] == installer.resolve(Dependency('baz', version_eq='1.0'), dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz==1.0', 'bar==1.0'] == installer.resolve(Dependency('baz', version_eq='1.0'), dict(packages=['baz', 'bar'])) + assert ['baz==1.0'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz']), Dependency('baz', version_eq='1.0')) + assert ['baz==1.0', 'bar==1.0'] == installer.resolve(dict(packages=['baz', 'bar']), Dependency('baz', version_eq='1.0')) # version_gte - assert ['baz>=1.0'] == installer.resolve(Dependency('baz', version_gte='1.0'), dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz>=1.0', 'bar>=1.0'] == installer.resolve(Dependency('baz', version_gte='1.0'), dict(packages=['baz', 'bar'])) + assert ['baz>=1.0'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz']), Dependency('baz', version_gte='1.0')) + assert ['baz>=1.0', 'bar>=1.0'] == installer.resolve(dict(packages=['baz', 'bar']), Dependency('baz', version_gte='1.0')) # version_lte - assert ['baz<=1.0'] == installer.resolve(Dependency('baz', version_lte='1.0'), dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz<=1.0', 'bar<=1.0'] == installer.resolve(Dependency('baz', version_lte='1.0'), dict(packages=['baz', 'bar'])) + assert ['baz<=1.0'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz']), Dependency('baz', version_lte='1.0')) + assert ['baz<=1.0', 'bar<=1.0'] == installer.resolve(dict(packages=['baz', 'bar']), Dependency('baz', version_lte='1.0')) # version_gt - assert ['baz>1.0'] == installer.resolve(Dependency('baz', version_gt='1.0'), dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz>1.0', 'bar>1.0'] == installer.resolve(Dependency('baz', version_gt='1.0'), dict(packages=['baz', 'bar'])) + assert ['baz>1.0'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz']), Dependency('baz', version_gt='1.0')) + assert ['baz>1.0', 'bar>1.0'] == installer.resolve(dict(packages=['baz', 'bar']), Dependency('baz', version_gt='1.0')) # version_lt - assert ['baz<1.0'] == installer.resolve(Dependency('baz', version_lt='1.0'), dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz<1.0', 'bar<1.0'] == installer.resolve(Dependency('baz', version_lt='1.0'), dict(packages=['baz', 'bar'])) + assert ['baz<1.0'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz']), Dependency('baz', version_lt='1.0')) + assert ['baz<1.0', 'bar<1.0'] == installer.resolve(dict(packages=['baz', 'bar']), Dependency('baz', version_lt='1.0')) # test invalid data try: - installer.resolve({}, 0) + installer.resolve(0, {}) assert False, 'should have raised' except InvalidData: pass diff --git a/test/test_rosdep_source.py b/test/test_rosdep_source.py index 37a76feff..6d7555e4c 100644 --- a/test/test_rosdep_source.py +++ b/test/test_rosdep_source.py @@ -191,7 +191,6 @@ def test_SourceInstaller_get_install_command(): def test_SourceInstaller_resolve(): - from catkin_pkg.package import Dependency from rosdep2.platforms.source import SourceInstaller, InvalidData test_dir = get_test_dir() @@ -201,16 +200,16 @@ def test_SourceInstaller_resolve(): installer = SourceInstaller() try: - installer.resolve(Dependency('null'), {}) + installer.resolve({}) assert False, 'should have raised' except InvalidData: pass try: - installer.resolve(Dependency('null'), dict(uri=url, md5sum=md5sum_bad)) + installer.resolve(dict(uri=url, md5sum=md5sum_bad)) assert False, 'should have raised' except InvalidData: pass - resolved = installer.resolve(Dependency('null'), dict(uri=url, md5sum=md5sum_good)) + resolved = installer.resolve(dict(uri=url, md5sum=md5sum_good)) assert type(resolved) == list assert len(resolved) == 1 @@ -223,7 +222,7 @@ def test_SourceInstaller_resolve(): assert resolved.check_presence_command == rep122_check_presence_command # test again to activate caching - resolved = installer.resolve(Dependency('null'), dict(uri=url, md5sum=md5sum_good)) + resolved = installer.resolve(dict(uri=url, md5sum=md5sum_good)) assert type(resolved) == list, 'Cache should also return a list' assert len(resolved) == 1 resolved = resolved[0]