Skip to content

Commit

Permalink
resolve(self, rosdep,rosdep_arg_dict) move rosdep argument after rosd…
Browse files Browse the repository at this point in the history
…ep_args_dict adn add default value for backward compatibility
  • Loading branch information
k-okada committed Jun 16, 2022
1 parent 6d09a34 commit 8e1e84c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/rosdep2/catkin_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
7 changes: 4 additions & 3 deletions src/rosdep2/installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()`
"""
Expand Down
2 changes: 1 addition & 1 deletion src/rosdep2/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/rosdep2/platforms/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()`
"""
Expand Down Expand Up @@ -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 = []
Expand Down
4 changes: 3 additions & 1 deletion src/rosdep2/platforms/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()`
"""
Expand Down
6 changes: 4 additions & 2 deletions src/rosdep2/platforms/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions test/test_rosdep_installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_Installer_tripwire():
except NotImplementedError:
pass
try:
Installer().resolve(Dependency('null'), {})
Installer().resolve({})
assert False
except NotImplementedError:
pass
Expand Down Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions test/test_rosdep_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions test/test_rosdep_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 8e1e84c

Please sign in to comment.