Skip to content

Commit

Permalink
Fix cached dependency manager.
Browse files Browse the repository at this point in the history
Broken with baf9b82.

Also fix test case that made me think it was okay in the first place.
  • Loading branch information
jmchilton committed Jan 24, 2017
1 parent c85b28c commit df8be3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lib/galaxy/tools/deps/__init__.py
Expand Up @@ -36,7 +36,6 @@ def build_dependency_manager( config ):
'app_config': config,
}
if getattr(config, "use_cached_dependency_manager", False):
dependency_manager_kwds['tool_dependency_cache_dir'] = config.tool_dependency_cache_dir
dependency_manager = CachedDependencyManager(**dependency_manager_kwds)
else:
dependency_manager = DependencyManager( **dependency_manager_kwds )
Expand Down Expand Up @@ -92,15 +91,20 @@ def get_resolver_option(self, resolver, key, explicit_resolver_options={}):
global_key = "%s_%s" % (config_prefix, key)
value = explicit_resolver_options.get(key, CONFIG_VAL_NOT_FOUND)
if value is CONFIG_VAL_NOT_FOUND:
if isinstance(self.__app_config, dict):
value = self.__app_config.get(global_key, CONFIG_VAL_NOT_FOUND)
else:
value = getattr(self.__app_config, global_key, CONFIG_VAL_NOT_FOUND)
value = self.get_app_option(global_key, default)

return value

def get_app_option(self, key, default=None):
value = CONFIG_VAL_NOT_FOUND
if isinstance(self.__app_config, dict):
value = self.__app_config.get(key, CONFIG_VAL_NOT_FOUND)
else:
value = getattr(self.__app_config, key, CONFIG_VAL_NOT_FOUND)
if value is CONFIG_VAL_NOT_FOUND and hasattr(self.__app_config, "config_dict"):
value = self.__app_config.config_dict.get(global_key, CONFIG_VAL_NOT_FOUND)
value = self.__app_config.config_dict.get(key, CONFIG_VAL_NOT_FOUND)
if value is CONFIG_VAL_NOT_FOUND:
value = default

return value

def dependency_shell_commands( self, requirements, **kwds ):
Expand Down Expand Up @@ -210,8 +214,9 @@ def __resolvers_dict( self ):


class CachedDependencyManager(DependencyManager):
def __init__(self, default_base_path, conf_file=None, app_config={}):
def __init__(self, default_base_path, conf_file=None, app_config={}, tool_dependency_cache_dir=None):
super(CachedDependencyManager, self).__init__(default_base_path=default_base_path, conf_file=conf_file, app_config=app_config)
self.tool_dependency_cache_dir = self.get_app_option("tool_dependency_cache_dir")

def build_cache(self, requirements, **kwds):
resolved_dependencies = self.requirements_to_dependencies(requirements, **kwds)
Expand Down Expand Up @@ -240,7 +245,7 @@ def dependency_shell_commands( self, requirements, **kwds ):
resolved_dependencies = self.requirements_to_dependencies(requirements, **kwds)
cacheable_dependencies = [dep for dep in resolved_dependencies.values() if dep.cacheable]
hashed_dependencies_dir = self.get_hashed_dependencies_path(cacheable_dependencies)
if not os.path.exists(hashed_dependencies_dir) and self.__app_config.getattr("precache_dependencies", False):
if not os.path.exists(hashed_dependencies_dir) and self.get_app_option("precache_dependencies", False):
# Cache not present, try to create it
self.build_cache(requirements, **kwds)
if os.path.exists(hashed_dependencies_dir):
Expand All @@ -265,4 +270,4 @@ def get_hashed_dependencies_path(self, resolved_dependencies):
:rtype: str
"""
req_hashes = self.hash_dependencies(resolved_dependencies)
return os.path.abspath(os.path.join(self.extra_config['tool_dependency_cache_dir'], req_hashes))
return os.path.abspath(os.path.join(self.tool_dependency_cache_dir, req_hashes))
2 changes: 1 addition & 1 deletion test/integration/test_resolvers.py
Expand Up @@ -20,7 +20,7 @@ class CondaResolutionIntegrationTestCase(integration_util.IntegrationTestCase):
@classmethod
def handle_galaxy_config_kwds(cls, config):
cls.conda_tmp_prefix = mkdtemp()
config["use_cached_dep_manager"] = True
config["use_cached_dependency_manager"] = True
config["conda_auto_init"] = True
config["conda_prefix"] = os.path.join(cls.conda_tmp_prefix, 'conda')

Expand Down

0 comments on commit df8be3a

Please sign in to comment.