From cf769dd09deb73624b22628208fa103cc4f27150 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sun, 27 Nov 2016 16:38:34 +0100 Subject: [PATCH] Add API to install resolver tool dependencies and to build a tool dependency cache (if activated in galaxy.ini). An example to install dependencies for the twobit converter: ``` import bioblend.galaxy url = 'http://localhost:8080/' api_key = 'admin_api_key' tool_id = 'CONVERTER_fasta_to_2bit' endpoint = "api/tools/%s/install_dependencies" % tool_id gi = bioblend.galaxy.GalaxyInstance(url, api_key) gi.make_post_request("/".join((url, endpoint)), payload={'id': tool_id}) ``` If `use_cached_dependency_manager` is activated in the galaxy.ini, a cached environment can be built like this: ``` endpoint = "api/tools/%s/build_dependency_cache" % tool_id gi.make_post_request("/".join((url, endpoint)), payload={'id': tool_id}) ``` --- .../datatypes/converters/fasta_to_2bit.xml | 1 + lib/galaxy/webapps/galaxy/api/tools.py | 27 +++++++++++++++++++ lib/galaxy/webapps/galaxy/buildapp.py | 2 ++ 3 files changed, 30 insertions(+) diff --git a/lib/galaxy/datatypes/converters/fasta_to_2bit.xml b/lib/galaxy/datatypes/converters/fasta_to_2bit.xml index a8e3bb3204f..f0e004661fb 100644 --- a/lib/galaxy/datatypes/converters/fasta_to_2bit.xml +++ b/lib/galaxy/datatypes/converters/fasta_to_2bit.xml @@ -2,6 +2,7 @@ + ucsc-twobittofa ucsc_tools faToTwoBit '$input' '$output' diff --git a/lib/galaxy/webapps/galaxy/api/tools.py b/lib/galaxy/webapps/galaxy/api/tools.py index 8dc7372738c..f91081d6b82 100644 --- a/lib/galaxy/webapps/galaxy/api/tools.py +++ b/lib/galaxy/webapps/galaxy/api/tools.py @@ -129,6 +129,33 @@ class ToolsController( BaseAPIController, UsesVisualizationMixin ): tool = self._get_tool(id) return tool.tool_requirements_status + @expose_api + @web.require_admin + def install_dependencies(self, trans, id, **kwds): + """ + POST /api/tools/{tool_id}/install_dependencies + Attempts to install requirements via the dependency resolver + """ + 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() + # 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 + + @expose_api + @web.require_admin + def build_dependency_cache(self, trans, id, **kwds): + """ + POST /api/tools/{tool_id}/build_dependency_cache + Attempts to cache installed dependencies. + """ + tool = self._get_tool(id) + tool.build_dependency_cache() + # TODO: Should also have a more meaningful return. + return tool.tool_requirements_status + @expose_api @web.require_admin def diagnostics( self, trans, id, **kwd ): diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index 53d0c948383..75eee3a7d4b 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -262,6 +262,8 @@ def populate_api_routes( webapp, app ): webapp.mapper.connect( '/api/tools/{id:.+?}/citations', action='citations', controller="tools" ) webapp.mapper.connect( '/api/tools/{id:.+?}/download', action='download', controller="tools" ) webapp.mapper.connect( '/api/tools/{id:.+?}/requirements', action='requirements', controller="tools") + webapp.mapper.connect( '/api/tools/{id:.+?}/install_dependencies', action='install_dependencies', controller="tools", conditions=dict( method=[ "POST" ] )) + webapp.mapper.connect( '/api/tools/{id:.+?}/build_dependency_cache', action='build_dependency_cache', controller="tools", conditions=dict( method=[ "POST" ] )) webapp.mapper.connect( '/api/tools/{id:.+?}', action='show', controller="tools" ) webapp.mapper.resource( 'tool', 'tools', path_prefix='/api' )