Skip to content

Commit

Permalink
Change interface of depependency resolver's resolve for consistency.
Browse files Browse the repository at this point in the history
If resolve_all takes in requirements, then so should resolve.
  • Loading branch information
jmchilton committed Jan 18, 2017
1 parent 5fc5ab1 commit 6de74a7
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 20 deletions.
12 changes: 1 addition & 11 deletions lib/galaxy/tools/deps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,7 @@ def _requirements_to_dependencies_dict(self, requirements, **kwds):
continue

if requirement.type in ['package', 'set_environment']:
name = requirement.name
version = requirement.version
specs = requirement.specs

if hasattr(resolver, "find_specification"):
spec = resolver.find_specification(specs)
if spec is not None:
name = spec.short_name
version = spec.version or version

dependency = resolver.resolve( name, version, requirement.type, **kwds )
dependency = resolver.resolve( requirement, **kwds )
if require_exact and not dependency.exact:
continue

Expand Down
5 changes: 5 additions & 0 deletions lib/galaxy/tools/deps/requirements.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import copy

from galaxy.util import asbool, xml_text

DEFAULT_REQUIREMENT_TYPE = "package"
Expand All @@ -20,6 +22,9 @@ def to_dict( self ):
specs = [s.to_dict() for s in self.specs]
return dict(name=self.name, type=self.type, version=self.version, specs=specs)

def copy( self ):
return copy.deepcopy( self )

@staticmethod
def from_dict( dict ):
version = dict.get( "version", None )
Expand Down
18 changes: 17 additions & 1 deletion lib/galaxy/tools/deps/resolvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DependencyResolver(Dictifiable, object):
__metaclass__ = ABCMeta

@abstractmethod
def resolve( self, name, version, type, **kwds ):
def resolve( self, requirement, **kwds ):
"""Given inputs describing dependency in the abstract yield a Dependency object.
The Dependency object describes various attributes (script, bin,
Expand Down Expand Up @@ -92,6 +92,22 @@ def find_specification(self, specs):
return spec
return None

def resolve_specs(self, requirement):
name = requirement.name
version = requirement.version
specs = requirement.specs

spec = self.find_specification(specs)
if spec is not None:
name = spec.short_name
version = spec.version or version

requirement = requirement.copy()
requirement.name = name
requirement.version = version

return requirement


class InstallableDependencyResolver:
""" Mix this into a ``DependencyResolver`` and implement to indicate
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tools/deps/resolvers/brewed_tool_shed_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, dependency_manager, **kwds):
self._init_homebrew(**kwds)
self._init_base_path(dependency_manager, **kwds)

def resolve(self, name, version, type, **kwds):
def resolve(self, requirement, **kwds):
name, version, type = requirement.name, requirement.version, requirement.type
if type != "package":
return NullDependency(version=version, name=name)
if version is None:
Expand Down
7 changes: 6 additions & 1 deletion lib/galaxy/tools/deps/resolvers/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def resolve_all(self, requirements, **kwds):

conda_targets = []
for requirement in requirements:
requirement = self.resolve_specs(requirement)

version = requirement.version
if self.versionless:
version = None
Expand Down Expand Up @@ -183,7 +185,10 @@ def merged_environment_name(self, conda_targets):
assert len(conda_targets) == 1
return conda_targets[0].install_environment

def resolve(self, name, version, type, **kwds):
def resolve(self, requirement, **kwds):
requirement = self.resolve_specs(requirement)
name, version, type = requirement.name, requirement.version, requirement.type

# Check for conda just not being there, this way we can enable
# conda by default and just do nothing in not configured.
if not os.path.isdir(self.conda_context.conda_prefix):
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/tools/deps/resolvers/galaxy_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ def __init__(self, dependency_manager, **kwds):
self.versionless = str(kwds.get('versionless', "false")).lower() == "true"
self._init_base_path( dependency_manager, **kwds )

def resolve( self, name, version, type, **kwds ):
def resolve(self, requirement, **kwds):
"""
Attempt to find a dependency named `name` at version `version`. If version is None, return the "default" version as determined using a
symbolic link (if found). Returns a triple of: env_script, base_path, real_version
"""
name, version, type = requirement.name, requirement.version, requirement.type

if version is None or self.versionless:
exact = not self.versionless or version is None
return self._find_dep_default( name, type=type, exact=exact, **kwds )
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/tools/deps/resolvers/homebrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def __init__(self, dependency_manager, **kwds):

self._init_homebrew(**kwds)

def resolve(self, name, version, type, **kwds):
def resolve(self, requirement, **kwds):
name, version, type = requirement.name, requirement.version, requirement.type

if type != "package":
return NullDependency(version=version, name=name)

Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/tools/deps/resolvers/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def __default_modulespath(self):
module_path = DEFAULT_MODULE_PATH
return module_path

def resolve( self, name, version, type, **kwds ):
def resolve(self, requirement, **kwds):
name, version, type = requirement.name, requirement.version, requirement.type

if type != "package":
return NullDependency(version=version, name=name)

Expand Down
7 changes: 4 additions & 3 deletions test/unit/tools/test_tool_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from subprocess import PIPE, Popen

from galaxy.tools.deps import DependencyManager
from galaxy.tools.deps.requirements import ToolRequirement
from galaxy.tools.deps.resolvers import NullDependency
from galaxy.tools.deps.resolvers.galaxy_packages import GalaxyPackageDependency
from galaxy.tools.deps.resolvers.modules import ModuleDependency, ModuleDependencyResolver
Expand Down Expand Up @@ -141,15 +142,15 @@ def test_module_dependency_resolver():
advisor/2013/update3 intel/12.0 mkl/10.2.7.041
''')
resolver = ModuleDependencyResolver(None, modulecmd=module_script)
module = resolver.resolve( name="R", version=None, type="package" )
module = resolver.resolve( ToolRequirement( name="R", version=None, type="package" ) )
assert module.module_name == "R"
assert module.module_version is None

module = resolver.resolve( name="R", version="3.0.1", type="package" )
module = resolver.resolve( ToolRequirement( name="R", version="3.0.1", type="package" ) )
assert module.module_name == "R"
assert module.module_version == "3.0.1"

module = resolver.resolve( name="R", version="3.0.4", type="package" )
module = resolver.resolve( ToolRequirement( name="R", version="3.0.4", type="package" ) )
assert isinstance(module, NullDependency)


Expand Down

0 comments on commit 6de74a7

Please sign in to comment.