From 045a2f0d471f7b4186aff625f3cea9abfa549fa2 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sun, 27 Nov 2016 18:39:13 +0100 Subject: [PATCH] Add `force_rebuild` param to build_dependency_cache This will remove a pre-existing cached dependency directory. --- lib/galaxy/tools/__init__.py | 5 +++-- lib/galaxy/tools/deps/__init__.py | 7 +++++++ lib/galaxy/webapps/galaxy/api/tools.py | 11 +++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 34a34b37f31..ba8ee6ce1a2 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -1306,7 +1306,7 @@ class Tool( object, Dictifiable ): visit_input_values( self.inputs, values, validate_inputs ) return messages - def build_dependency_cache(self): + def build_dependency_cache(self, **kwds): if isinstance(self.app.toolbox.dependency_manager, CachedDependencyManager): self.app.toolbox.dependency_manager.build_cache( requirements=self.requirements, @@ -1314,7 +1314,8 @@ class Tool( object, Dictifiable ): tool_dir=self.tool_dir, job_directory=None, metadata=False, - tool_instance=self + tool_instance=self, + **kwds ) def build_dependency_shell_commands( self, job_directory=None, metadata=False ): diff --git a/lib/galaxy/tools/deps/__init__.py b/lib/galaxy/tools/deps/__init__.py index 4f0a6d2a7d4..640726f73d9 100644 --- a/lib/galaxy/tools/deps/__init__.py +++ b/lib/galaxy/tools/deps/__init__.py @@ -5,6 +5,7 @@ Dependency management for tools. import json import logging import os.path +import shutil from collections import OrderedDict @@ -175,6 +176,12 @@ class CachedDependencyManager(DependencyManager): resolved_dependencies = self.requirements_to_dependencies(requirements, **kwds) cacheable_dependencies = [dep for req, dep in resolved_dependencies.items() if dep.cacheable] hashed_requirements_dir = self.get_hashed_requirements_path(cacheable_dependencies) + if kwds.get('force_rebuild', False) and os.path.exists(hashed_requirements_dir): + try: + shutil.rmtree(hashed_requirements_dir) + except Exception: + log.warning("Could not delete cached requirements directory '%s'" % hashed_requirements_dir) + pass [dep.build_cache(hashed_requirements_dir) for dep in cacheable_dependencies] def dependency_shell_commands( self, requirements, **kwds ): diff --git a/lib/galaxy/webapps/galaxy/api/tools.py b/lib/galaxy/webapps/galaxy/api/tools.py index f91081d6b82..b76dd9a3f40 100644 --- a/lib/galaxy/webapps/galaxy/api/tools.py +++ b/lib/galaxy/webapps/galaxy/api/tools.py @@ -135,11 +135,15 @@ class ToolsController( BaseAPIController, UsesVisualizationMixin ): """ POST /api/tools/{tool_id}/install_dependencies Attempts to install requirements via the dependency resolver + + parameters: + build_dependency_cache: If true, attempts to cache dependencies for this tool + force_rebuild: If true and chache dir exists, attempts to delete cache dir """ tool = self._get_tool(id) [tool._view.install_dependency(id=None, **req.to_dict()) for req in tool.requirements] if kwds.get('build_dependency_cache'): - tool.build_dependency_cache() + tool.build_dependency_cache(**kwds) # TODO: rework resolver install system to log and report what has been done. # _view.install_dependency should return a dict with stdout, stderr and success status return tool.tool_requirements_status @@ -150,9 +154,12 @@ class ToolsController( BaseAPIController, UsesVisualizationMixin ): """ POST /api/tools/{tool_id}/build_dependency_cache Attempts to cache installed dependencies. + + parameters: + force_rebuild: If true and chache dir exists, attempts to delete cache dir """ tool = self._get_tool(id) - tool.build_dependency_cache() + tool.build_dependency_cache(**kwds) # TODO: Should also have a more meaningful return. return tool.tool_requirements_status