From 16b49d9140edbf116f83b51b957cd61c4f2d91df Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sun, 27 Nov 2016 23:16:56 +0100 Subject: [PATCH] Add dependency_resolvers/clean endpoint --- lib/galaxy/tools/deps/resolvers/conda.py | 4 ++++ lib/galaxy/tools/deps/views.py | 14 ++++++++++++++ .../webapps/galaxy/api/tool_dependencies.py | 19 +++++++++++++++++++ lib/galaxy/webapps/galaxy/buildapp.py | 1 + test/integration/test_resolvers.py | 7 +++++++ 5 files changed, 45 insertions(+) diff --git a/lib/galaxy/tools/deps/resolvers/conda.py b/lib/galaxy/tools/deps/resolvers/conda.py index 5751212626e..beb06871028 100644 --- a/lib/galaxy/tools/deps/resolvers/conda.py +++ b/lib/galaxy/tools/deps/resolvers/conda.py @@ -11,6 +11,7 @@ import galaxy.tools.deps.installable from ..conda_util import ( build_isolated_environment, cleanup_failed_install, + exec_clean, CondaContext, CondaTarget, install_conda, @@ -98,6 +99,9 @@ class CondaDependencyResolver(DependencyResolver, ListableDependencyResolver, In self.auto_install = auto_install self.copy_dependencies = copy_dependencies + def clean(self, **kwds): + return exec_clean() + def resolve(self, name, version, type, **kwds): # Check for conda just not being there, this way we can enable # conda by default and just do nothing in not configured. diff --git a/lib/galaxy/tools/deps/views.py b/lib/galaxy/tools/deps/views.py index be4be6458b3..0735d4af4c8 100644 --- a/lib/galaxy/tools/deps/views.py +++ b/lib/galaxy/tools/deps/views.py @@ -125,5 +125,19 @@ class DependencyResolversView(object): """ return [index for index, resolver in enumerate(self._dependency_resolvers) if hasattr(resolver, "install_dependency") and not resolver.disabled ] + def get_requirements_status(self, requested_requirements, installed_tool_dependencies=None): return [self.manager_dependency(installed_tool_dependencies=installed_tool_dependencies, **req) for req in requested_requirements] + + def clean(self, index=None, **kwds): + if index: + resolver = self._dependency_resolver(index) + if not hasattr(resolver, "clean"): + raise NotImplemented() + else: + resolver.clean() + return "OK" + else: + [resolver.clean(**kwds) for resolver in self._dependency_resolvers if hasattr(resolver, 'clean')] + return "OK" + diff --git a/lib/galaxy/webapps/galaxy/api/tool_dependencies.py b/lib/galaxy/webapps/galaxy/api/tool_dependencies.py index f91c93ff5a5..cd961472355 100644 --- a/lib/galaxy/webapps/galaxy/api/tool_dependencies.py +++ b/lib/galaxy/webapps/galaxy/api/tool_dependencies.py @@ -162,3 +162,22 @@ class ToolDependenciesAPIController( BaseAPIController ): the corresponding resolver (keyed on 'index'). """ return self._view.manager_requirements() + + @expose_api + @require_admin + def clean(self, trans, id=None, **kwds): + """ + POST /api/dependencies_resolver/clean + + Cleans up intermediate files created by resolvers during the dependency + installation. + + :type index: int + :param index: index of the dependency resolver + + :rtype: dict + :returns: a dictified description of the requirement that could + be resolved (keyed on 'requirement') and the index of + the corresponding resolver (keyed on 'index'). + """ + return self._view.clean(id, **kwds) diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index 75eee3a7d4b..52b9fb3882a 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -270,6 +270,7 @@ def populate_api_routes( webapp, app ): webapp.mapper.connect( '/api/dependency_resolvers/dependency', action="manager_dependency", controller="tool_dependencies", conditions=dict( method=[ "GET" ] ) ) webapp.mapper.connect( '/api/dependency_resolvers/dependency', action="install_dependency", controller="tool_dependencies", conditions=dict( method=[ "POST" ] ) ) webapp.mapper.connect( '/api/dependency_resolvers/requirements', action="manager_requirements", controller="tool_dependencies" ) + webapp.mapper.connect('/api/dependency_resolvers/clean', action="clean", controller="tool_dependencies", conditions=dict(method=["POST"])) webapp.mapper.connect( '/api/dependency_resolvers/{id}/dependency', action="resolver_dependency", controller="tool_dependencies", conditions=dict( method=[ "GET" ] ) ) webapp.mapper.connect( '/api/dependency_resolvers/{id}/dependency', action="install_dependency", controller="tool_dependencies", conditions=dict( method=[ "POST" ] ) ) webapp.mapper.connect( '/api/dependency_resolvers/{id}/requirements', action="resolver_requirements", controller="tool_dependencies" ) diff --git a/test/integration/test_resolvers.py b/test/integration/test_resolvers.py index cf8993f0e8a..d2f1208432f 100644 --- a/test/integration/test_resolvers.py +++ b/test/integration/test_resolvers.py @@ -95,3 +95,10 @@ class CondaResolutionIntegrationTestCase(integration_util.IntegrationTestCase, A endpoint = "tools/%s/build_dependency_cache" % tool_id create_response = self._post(endpoint, data=data, admin=True) self._assert_status_code_is( create_response, 200 ) + + def test_conda_clean( self ): + endpoint = 'dependencies_resolvers/clean' + create_response = self._post(endpoint, data={}, admin=True) + self._assert_status_code_is(create_response, 200) + response = create_response.json() + assert response == "OK" \ No newline at end of file