From 604affea172d3a1f3b44d9cb86d101a26c7b8dad Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Thu, 18 Jul 2019 09:52:19 +0000 Subject: [PATCH] support veresion specific install for pip (and others) --- src/rosdep2/installers.py | 5 ++-- src/rosdep2/lookup.py | 40 +++++++++++++++------------ src/rosdep2/main.py | 2 +- src/rosdep2/platforms/osx.py | 4 +-- src/rosdep2/platforms/pip.py | 49 ++++++++++++++++++++++++++++++++- src/rosdep2/platforms/source.py | 4 +-- src/rosdep2/rospkg_loader.py | 27 ++++++++++++++++-- test/test_rosdep_installers.py | 22 ++++++++------- test/test_rosdep_lookup.py | 33 ++++++++++++---------- test/test_rosdep_pip.py | 42 ++++++++++++++++++++++++++++ test/test_rosdep_source.py | 9 +++--- 11 files changed, 179 insertions(+), 58 deletions(-) diff --git a/src/rosdep2/installers.py b/src/rosdep2/installers.py index 2f4c1cd1e2..a1d2b6b09f 100644 --- a/src/rosdep2/installers.py +++ b/src/rosdep2/installers.py @@ -278,8 +278,9 @@ def get_depends(self, rosdep_args): """ return [] # Default return empty list - def resolve(self, rosdep_args_dict): + def resolve(self, rosdep, rosdep_args_dict): """ + :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 :returns: [resolutions]. resolved objects should be printable to a user, but are otherwise opaque. """ @@ -336,7 +337,7 @@ def elevate_priv(self, cmd): """ return (self.sudo_command.split() if self.as_root else []) + cmd - def resolve(self, rosdep_args): + def resolve(self, rosdep, rosdep_args): """ See :meth:`Installer.resolve()` """ diff --git a/src/rosdep2/lookup.py b/src/rosdep2/lookup.py index 29eeb9d39b..36f3bb6f14 100644 --- a/src/rosdep2/lookup.py +++ b/src/rosdep2/lookup.py @@ -226,10 +226,11 @@ def merge(self, update_entry, override=False, verbose=False): db[dep_name].reverse_merge(dep_data, update_entry.origin, verbose=verbose) -def prune_catkin_packages(rosdep_keys, verbose=False): +def prune_catkin_packages(rosdeps, verbose=False): workspace_pkgs = catkin_packages.get_workspace_packages() if not workspace_pkgs: - return rosdep_keys + return rosdeps + rosdep_keys = [d.name for d in rosdeps] for i, rosdep_key in reversed(list(enumerate(rosdep_keys))): if rosdep_key in workspace_pkgs: # If workspace packages listed (--catkin-workspace) @@ -239,13 +240,14 @@ def prune_catkin_packages(rosdep_keys, verbose=False): print("rosdep key '{0}'".format(rosdep_key) + ' is in the catkin workspace, skipping.', file=sys.stderr) - del rosdep_keys[i] - return rosdep_keys + del rosdeps[i] + return rosdeps -def prune_skipped_packages(rosdep_keys, skipped_keys, verbose=False): +def prune_skipped_packages(rosdeps, skipped_keys, verbose=False): if not skipped_keys: - return rosdep_keys + return rosdeps + rosdep_keys = [d.name for d in rosdeps] for i, rosdep_key in reversed(list(enumerate(rosdep_keys))): if rosdep_key in skipped_keys: # If the key is in the list of keys to explicitly skip, skip it @@ -253,8 +255,8 @@ def prune_skipped_packages(rosdep_keys, skipped_keys, verbose=False): print("rosdep key '{0}'".format(rosdep_key) + ' was listed in the skipped packages, skipping.', file=sys.stderr) - del rosdep_keys[i] - return rosdep_keys + del rosdeps[i] + return rosdeps class RosdepLookup(object): @@ -320,7 +322,7 @@ def get_resources_that_need(self, rosdep_name): :returns: list of package names that require rosdep, ``[str]`` """ - return [k for k in self.loader.get_loadable_resources() if rosdep_name in self.get_rosdeps(k, implicit=False)] + return [k for k in self.loader.get_loadable_resources() if rosdep_name in [d.name for d in self.get_rosdeps(k, implicit=False)]] @staticmethod def create_from_rospkg(rospack=None, rosstack=None, @@ -390,15 +392,16 @@ def resolve_all(self, resources, installer_context, implicit=False): # TODO: resolutions dictionary should be replaced with resolution model instead of mapping (undefined) keys. for resource_name in resources: try: - rosdep_keys = self.get_rosdeps(resource_name, implicit=implicit) + rosdeps = self.get_rosdeps(resource_name, implicit=implicit) if self.verbose: - print('resolve_all: resource [%s] requires rosdep keys [%s]' % (resource_name, ', '.join(rosdep_keys)), file=sys.stderr) - rosdep_keys = prune_catkin_packages(rosdep_keys, self.verbose) - rosdep_keys = prune_skipped_packages(rosdep_keys, self.skipped_keys, self.verbose) - for rosdep_key in rosdep_keys: + print('resolve_all: resource [%s] requires rosdep keys [%s]' % (resource_name, ', '.join([d.name for d in rosdeps])), file=sys.stderr) + rosdeps = prune_catkin_packages(rosdeps, self.verbose) + rosdeps = prune_skipped_packages(rosdeps, self.skipped_keys, self.verbose) + for rosdep in rosdeps: try: installer_key, resolution, dependencies = \ - self.resolve(rosdep_key, resource_name, installer_context) + self.resolve(rosdep, resource_name, installer_context) + rosdep_key = rosdep.name depend_graph[rosdep_key]['installer_key'] = installer_key depend_graph[rosdep_key]['install_keys'] = list(resolution) depend_graph[rosdep_key]['dependencies'] = list(dependencies) @@ -430,13 +433,13 @@ def resolve_all(self, resources, installer_context, implicit=False): return resolutions_flat, errors - def resolve(self, rosdep_key, resource_name, installer_context): + def resolve(self, rosdep, resource_name, installer_context): """ Resolve a :class:`RosdepDefinition` for a particular os/version spec. :param resource_name: resource (e.g. ROS package) to resolve key within - :param rosdep_key: rosdep key to resolve + :param rosdeps: rosdep key (catkin_pkg.package.Dependency object) to resolve :param os_name: OS name to use for resolution :param os_version: OS name to use for resolution @@ -450,6 +453,7 @@ def resolve(self, rosdep_key, resource_name, installer_context): :raises: :exc:`ResolutionError` If *rosdep_key* cannot be resolved for *resource_name* in *installer_context* :raises: :exc:`rospkg.ResourceNotFound` if *resource_name* cannot be located """ + rosdep_key = rosdep.name os_name, os_version = installer_context.get_os_name_and_version() view = self.get_rosdep_view_for_resource(resource_name) @@ -489,7 +493,7 @@ def resolve(self, rosdep_key, 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_args_dict) + resolution = installer.resolve(rosdep, rosdep_args_dict) dependencies = installer.get_depends(rosdep_args_dict) # cache value diff --git a/src/rosdep2/main.py b/src/rosdep2/main.py index 50a0bb4b63..939cc9adf7 100644 --- a/src/rosdep2/main.py +++ b/src/rosdep2/main.py @@ -619,7 +619,7 @@ def command_keys(lookup, packages, 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)) + print('\n'.join([d.name for d in rosdep_keys])) def get_keys(lookup, packages, recursive): diff --git a/src/rosdep2/platforms/osx.py b/src/rosdep2/platforms/osx.py index c17e811c0c..21a8488fde 100644 --- a/src/rosdep2/platforms/osx.py +++ b/src/rosdep2/platforms/osx.py @@ -281,7 +281,7 @@ def get_version_strings(self): except OSError: return ['Homebrew not-found'] - def resolve(self, rosdep_args): + def resolve(self, rosdep, rosdep_args): """ See :meth:`Installer.resolve()` """ @@ -318,7 +318,7 @@ def handle_options(options): return options - packages = super(HomebrewInstaller, self).resolve(rosdep_args) + packages = super(HomebrewInstaller, self).resolve(rosdep, rosdep_args) resolution = [] if packages: options = [] diff --git a/src/rosdep2/platforms/pip.py b/src/rosdep2/platforms/pip.py index 7ae8ffda44..e4649b1097 100644 --- a/src/rosdep2/platforms/pip.py +++ b/src/rosdep2/platforms/pip.py @@ -32,7 +32,7 @@ import pkg_resources import subprocess -from ..core import InstallFailed +from ..core import InstallFailed, InvalidData from ..installers import PackageManagerInstaller from ..shell_utils import read_stdout @@ -100,6 +100,53 @@ class PipInstaller(PackageManagerInstaller): def __init__(self): super(PipInstaller, self).__init__(pip_detect, supports_depends=True) + def resolve(self, rosdep, rosdep_args): + """ + See :meth:`Installer.resolve()` + """ + packages = None + if type(rosdep_args) == dict: + packages = rosdep_args.get('packages', []) + if isinstance(packages, str): + packages = packages.split() + elif isinstance(rosdep_args, str): + packages = rosdep_args.split(' ') + elif type(rosdep_args) == list: + packages = rosdep_args + else: + raise InvalidData('Invalid rosdep args: %s' % (rosdep_args)) + + pip_specify_version = None + if rosdep.version_eq: + for i, package in list(enumerate(packages)): + packages[i] = package + '==' + rosdep.version_eq + pip_specify_version = True + if rosdep.version_gte: + for i, package in list(enumerate(packages)): + package = package + ',' if pip_specify_version else package + packages[i] = package + '>=' + rosdep.version_gte + pip_specify_version = True + if rosdep.version_lte: + for i, package in list(enumerate(packages)): + package = package + ',' if pip_specify_version else package + packages[i] = package + '<=' + rosdep.version_lte + pip_specify_version = True + if rosdep.version_gt: + for i, package in list(enumerate(packages)): + package = package + ',' if pip_specify_version else package + packages[i] = package + '>' + rosdep.version_gt + pip_specify_version = True + if rosdep.version_lt: + for i, package in list(enumerate(packages)): + package = package + ',' if pip_specify_version else package + packages[i] = package + '<' + rosdep.version_lt + pip_specify_version = True + if pip_specify_version: + for i, package in list(enumerate(packages)): + packages[i] = "'" + package + "'" + + return packages + def get_version_strings(self): pip_version = pkg_resources.get_distribution('pip').version setuptools_version = pkg_resources.get_distribution('setuptools').version diff --git a/src/rosdep2/platforms/source.py b/src/rosdep2/platforms/source.py index 862494b729..afba83b4f3 100644 --- a/src/rosdep2/platforms/source.py +++ b/src/rosdep2/platforms/source.py @@ -201,7 +201,7 @@ def __init__(self): super(SourceInstaller, self).__init__(source_detect, supports_depends=True) self._rdmanifest_cache = {} - def resolve(self, rosdep_args): + def resolve(self, rosdep, rosdep_args): """ :raises: :exc:`InvalidData` If format invalid or unable to retrieve rdmanifests. @@ -246,7 +246,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/src/rosdep2/rospkg_loader.py b/src/rosdep2/rospkg_loader.py index 5b415675d1..f176a17641 100644 --- a/src/rosdep2/rospkg_loader.py +++ b/src/rosdep2/rospkg_loader.py @@ -136,14 +136,35 @@ def get_rosdeps(self, resource_name, implicit=True): :raises: :exc:`rospkg.ResourceNotFound` if *resource_name* cannot be found. """ - if resource_name in self.get_catkin_paths(): pkg = catkin_pkg.package.parse_package(self.get_catkin_paths()[resource_name]) pkg.evaluate_conditions(os.environ) deps = pkg.build_depends + pkg.buildtool_depends + pkg.run_depends + pkg.test_depends - return [d.name for d in deps if d.evaluated_condition] + return [d for d in deps if d.evaluated_condition] elif resource_name in self.get_loadable_resources(): - return self._rospack.get_rosdeps(resource_name, implicit=implicit) + # expand 'self._rospack.get_rosdeps(resource_name, implicit=implicit)' to return Dependency + def rospack_get_rosdeps(rospack, package, implicit=implicit): + if implicit: + return rospack_implicit_rosdeps(rospack, package) + else: + m = rospack.get_manifest(package) + return m.rosdeps + + def rospack_implicit_rosdeps(rospack, package): + # set the key before recursive call to prevent infinite case + s = set() + # take the union of all dependencies + packages = rospack.get_depends(package, implicit=True) + for p in packages: + s.update(rospack_get_rosdeps(rospack, p, implicit=False)) + # add in our own deps + m = rospack.get_manifest(package) + s.update(m.rosdeps) + # cache the return value as a list + s = list(s) + return s + + return rospack_get_rosdeps(self._rospack, resource_name, implicit) elif resource_name in self._rosstack.list(): # stacks currently do not have rosdeps of their own, implicit or otherwise return [] diff --git a/test/test_rosdep_installers.py b/test/test_rosdep_installers.py index 0d71e8f45f..add1072401 100644 --- a/test/test_rosdep_installers.py +++ b/test/test_rosdep_installers.py @@ -293,6 +293,7 @@ class FakeInstaller2(Installer): def test_Installer_tripwire(): + from catkin_pkg.package import Dependency from rosdep2.installers import Installer try: Installer().is_installed('foo') @@ -305,7 +306,7 @@ def test_Installer_tripwire(): except NotImplementedError: pass try: - Installer().resolve({}) + Installer().resolve(Dependency('null'), {}) assert False except NotImplementedError: pass @@ -340,26 +341,27 @@ def test_PackageManagerInstaller(): def test_PackageManagerInstaller_resolve(): + from catkin_pkg.package import Dependency from rosdep2 import InvalidData from rosdep2.installers import PackageManagerInstaller installer = PackageManagerInstaller(detect_fn_all) - assert ['baz'] == installer.resolve(dict(depends=['foo', 'bar'], packages=['baz'])) - assert ['baz', 'bar'] == installer.resolve(dict(packages=['baz', 'bar'])) + assert ['baz'] == installer.resolve(Dependency('baz'), dict(depends=['foo', 'bar'], packages=['baz'])) + assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), dict(packages=['baz', 'bar'])) # test string logic - assert ['baz'] == installer.resolve(dict(depends=['foo', 'bar'], packages='baz')) - assert ['baz', 'bar'] == installer.resolve(dict(packages='baz bar')) - assert ['baz'] == installer.resolve('baz') - assert ['baz', 'bar'] == installer.resolve('baz bar') + 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') # test list logic - assert ['baz'] == installer.resolve(['baz']) - assert ['baz', 'bar'] == installer.resolve(['baz', 'bar']) + assert ['baz'] == installer.resolve(Dependency('baz'), ['baz']) + assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), ['baz', 'bar']) # test invalid data try: - installer.resolve(0) + installer.resolve(Dependency('baz'), 0) assert False, 'should have raised' except InvalidData: pass diff --git a/test/test_rosdep_lookup.py b/test/test_rosdep_lookup.py index 30f26877af..79e43b2619 100644 --- a/test/test_rosdep_lookup.py +++ b/test/test_rosdep_lookup.py @@ -288,25 +288,26 @@ def test_RosdepLookup_get_rosdeps(): pass print(lookup.get_rosdeps('stack1_p1')) - assert set(lookup.get_rosdeps('stack1_p1')) == set(['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) - assert set(lookup.get_rosdeps('stack1_p1', implicit=False)) == set(['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) + assert set([d.name for d in lookup.get_rosdeps('stack1_p1')]) == set(['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) + assert set([d.name for d in lookup.get_rosdeps('stack1_p1', implicit=False)]) == set(['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) print(lookup.get_rosdeps('stack1_p2')) - assert set(lookup.get_rosdeps('stack1_p2', implicit=False)) == set(['stack1_dep1', 'stack1_dep2', 'stack1_p2_dep1']), set(lookup.get_rosdeps('stack1_p2')) - assert set(lookup.get_rosdeps('stack1_p2', implicit=True)) == set(['stack1_dep1', 'stack1_dep2', 'stack1_p1_dep1', 'stack1_p1_dep2', 'stack1_p2_dep1']), set(lookup.get_rosdeps('stack1_p2')) + assert set([d.name for d in lookup.get_rosdeps('stack1_p2', implicit=False)]) == set(['stack1_dep1', 'stack1_dep2', 'stack1_p2_dep1']), set(lookup.get_rosdeps('stack1_p2')) + assert set([d.name for d in lookup.get_rosdeps('stack1_p2', implicit=True)]) == \ + set(['stack1_dep1', 'stack1_dep2', 'stack1_p1_dep1', 'stack1_p1_dep2', 'stack1_p2_dep1']), set([d.name for d in lookup.get_rosdeps('stack1_p2')]) # catkin print(lookup.get_rosdeps('simple_catkin_package')) - assert set(lookup.get_rosdeps('simple_catkin_package')) == set(['catkin', 'testboost']) - assert set(lookup.get_rosdeps('simple_catkin_package', implicit=False)) == set(['catkin', 'testboost']) + assert set([d.name for d in lookup.get_rosdeps('simple_catkin_package')]) == set(['catkin', 'testboost']) + assert set([d.name for d in lookup.get_rosdeps('simple_catkin_package', implicit=False)]) == set(['catkin', 'testboost']) print(lookup.get_rosdeps('another_catkin_package')) - assert set(lookup.get_rosdeps('another_catkin_package')) == set(['catkin', 'simple_catkin_package']) # implicit deps won't get included - assert set(lookup.get_rosdeps('another_catkin_package', implicit=False)) == set(['catkin', 'simple_catkin_package']) + assert set([d.name for d in lookup.get_rosdeps('another_catkin_package')]) == set(['catkin', 'simple_catkin_package']) # implicit deps won't get included + assert set([d.name for d in lookup.get_rosdeps('another_catkin_package', implicit=False)]) == set(['catkin', 'simple_catkin_package']) print(lookup.get_rosdeps('metapackage_with_deps')) - assert set(lookup.get_rosdeps('metapackage_with_deps')) == set(['catkin', 'simple_catkin_package', 'another_catkin_package']) # implicit deps won't get included - assert set(lookup.get_rosdeps('metapackage_with_deps', implicit=False)) == set(['catkin', 'simple_catkin_package', 'another_catkin_package']) + assert set([d.name for d in lookup.get_rosdeps('metapackage_with_deps')]) == set(['catkin', 'simple_catkin_package', 'another_catkin_package']) # implicit deps won't get included + assert set([d.name for d in lookup.get_rosdeps('metapackage_with_deps', implicit=False)]) == set(['catkin', 'simple_catkin_package', 'another_catkin_package']) def test_RosdepLookup_get_resources_that_need(): @@ -463,6 +464,7 @@ def test_RosdepLookup_resolve_all_errors(): def test_RosdepLookup_resolve_errors(): + from catkin_pkg.package import Dependency from rosdep2.installers import InstallerContext from rosdep2.lookup import RosdepLookup, ResolutionError rospack, rosstack = get_test_rospkgs() @@ -475,19 +477,20 @@ def test_RosdepLookup_resolve_errors(): installer_context.set_os_override('ubuntu', 'lucid') try: - lookup.resolve('testtinyxml', 'rospack_fake', installer_context) + lookup.resolve(Dependency('testtinyxml'), 'rospack_fake', installer_context) assert False, 'should have raised' except ResolutionError as e: assert 'Unsupported OS' in str(e), str(e) try: - lookup.resolve('fakedep', 'rospack_fake', installer_context) + lookup.resolve(Dependency('fakedep'), 'rospack_fake', installer_context) assert False, 'should have raised' except ResolutionError as e: assert 'Cannot locate rosdep definition' in str(e), str(e) def test_RosdepLookup_resolve(): + from catkin_pkg.package import Dependency from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() @@ -500,17 +503,17 @@ def test_RosdepLookup_resolve(): # repeat for caching for count in range(0, 2): - installer_key, resolution, dependencies = lookup.resolve('testtinyxml', 'rospack_fake', installer_context) + installer_key, resolution, dependencies = lookup.resolve(Dependency('testtinyxml'), 'rospack_fake', installer_context) assert 'apt' == installer_key assert ['libtinyxml-dev'] == resolution assert [] == dependencies - installer_key, resolution, dependencies = lookup.resolve('testboost', 'roscpp_fake', installer_context) + installer_key, resolution, dependencies = lookup.resolve(Dependency('testboost'), 'roscpp_fake', installer_context) assert 'apt' == installer_key assert ['libboost1.40-all-dev'] == resolution assert [] == dependencies - installer_key, resolution, dependencies = lookup.resolve('testlibtool', 'roscpp_fake', installer_context) + installer_key, resolution, dependencies = lookup.resolve(Dependency('testlibtool'), 'roscpp_fake', installer_context) assert 'apt' == installer_key assert set(['libtool', 'libltdl-dev']) == set(resolution) assert [] == dependencies diff --git a/test/test_rosdep_pip.py b/test/test_rosdep_pip.py index 9013d54fdf..4da1438d94 100644 --- a/test/test_rosdep_pip.py +++ b/test/test_rosdep_pip.py @@ -66,6 +66,48 @@ def test_PipInstaller_get_depends(): assert ['foo'] == installer.get_depends(dict(depends=['foo'])) +def test_PackageManagerInstaller_resolve(): + from rosdep2 import InvalidData + from rosdep2.platforms.pip import PipInstaller + 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'])) + + # 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') + + # test list logic + assert ['baz'] == installer.resolve(Dependency('baz'), ['baz']) + assert ['baz', 'bar'] == installer.resolve(Dependency('baz'), ['baz', 'bar']) + + # 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'])) + # 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'])) + # 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'])) + # 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'])) + # 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'])) + # test invalid data + try: + installer.resolve({}, 0) + assert False, 'should have raised' + except InvalidData: + pass + + def test_PipInstaller(): from rosdep2 import InstallFailed from rosdep2.platforms.pip import PipInstaller diff --git a/test/test_rosdep_source.py b/test/test_rosdep_source.py index 6d7555e4c9..37a76feffb 100644 --- a/test/test_rosdep_source.py +++ b/test/test_rosdep_source.py @@ -191,6 +191,7 @@ 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() @@ -200,16 +201,16 @@ def test_SourceInstaller_resolve(): installer = SourceInstaller() try: - installer.resolve({}) + installer.resolve(Dependency('null'), {}) assert False, 'should have raised' except InvalidData: pass try: - installer.resolve(dict(uri=url, md5sum=md5sum_bad)) + installer.resolve(Dependency('null'), dict(uri=url, md5sum=md5sum_bad)) assert False, 'should have raised' except InvalidData: pass - resolved = installer.resolve(dict(uri=url, md5sum=md5sum_good)) + resolved = installer.resolve(Dependency('null'), dict(uri=url, md5sum=md5sum_good)) assert type(resolved) == list assert len(resolved) == 1 @@ -222,7 +223,7 @@ def test_SourceInstaller_resolve(): assert resolved.check_presence_command == rep122_check_presence_command # test again to activate caching - resolved = installer.resolve(dict(uri=url, md5sum=md5sum_good)) + resolved = installer.resolve(Dependency('null'), dict(uri=url, md5sum=md5sum_good)) assert type(resolved) == list, 'Cache should also return a list' assert len(resolved) == 1 resolved = resolved[0]