From 7de5488c4e014164272ad94ef36d817aaa5c697e Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Thu, 10 Oct 2013 14:11:09 -0400 Subject: [PATCH] Filter tool dependency installation to only those that were checked when installing them from the Manage tool dependencies page for an installed tool shed repository. --- .../galaxy/controllers/admin_toolshed.py | 4 +- lib/tool_shed/util/common_install_util.py | 58 ++++++++++++------- lib/tool_shed/util/shed_util_common.py | 13 +++-- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py index 6930e3b20ef..06d37b0089b 100644 --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -701,11 +701,11 @@ class AdminToolshed( AdminGalaxy ): installed_tool_dependencies_select_field = suc.build_tool_dependencies_select_field( trans, tool_shed_repository=tool_shed_repository, name='inst_td_ids', - uninstalled=False ) + uninstalled_only=False ) uninstalled_tool_dependencies_select_field = suc.build_tool_dependencies_select_field( trans, tool_shed_repository=tool_shed_repository, name='uninstalled_tool_dependency_ids', - uninstalled=True ) + uninstalled_only=True ) return trans.fill_template( '/admin/tool_shed_repository/manage_repository_tool_dependencies.mako', repository=tool_shed_repository, installed_tool_dependencies_select_field=installed_tool_dependencies_select_field, diff --git a/lib/tool_shed/util/common_install_util.py b/lib/tool_shed/util/common_install_util.py index bc5ad8195de..0441060cce3 100644 --- a/lib/tool_shed/util/common_install_util.py +++ b/lib/tool_shed/util/common_install_util.py @@ -429,6 +429,10 @@ def handle_tool_dependencies( app, tool_shed_repository, tool_dependencies_confi will be installed in: ~////// """ + # The received list of tool_dependencies are the database records for those dependencies defined in the received tool_dependencies_config + # that should be installed. This allows for filtering out dependencies that have not been checked for installation on the 'Manage tool + # dependencies' page for an installed tool shed repository. + attr_tups_of_dependencies_for_install = [ ( td.name, td.version, td.type ) for td in tool_dependencies ] sa_session = app.model.context.current installed_tool_dependencies = [] # Parse the tool_dependencies.xml config. @@ -439,19 +443,43 @@ def handle_tool_dependencies( app, tool_shed_repository, tool_dependencies_confi fabric_version_checked = False for elem in root: if elem.tag == 'package': - # Only install the tool_dependency if it is not already installed. + # Only install the tool_dependency if it is not already installed and it is associated with a database record in the received + # tool_dependencies. package_name = elem.get( 'name', None ) package_version = elem.get( 'version', None ) if package_name and package_version: - for tool_dependency in tool_dependencies: - if tool_dependency.name==package_name and tool_dependency.version==package_version: - break - if tool_dependency.can_install: + attr_tup = ( package_name, package_version, 'package' ) + try: + index = attr_tups_of_dependencies_for_install.index( attr_tup ) + except Exception, e: + index = None + if index is not None: + tool_dependency = tool_dependencies[ index ] + if tool_dependency.can_install: + try: + tool_dependency = install_package( app, elem, tool_shed_repository, tool_dependencies=tool_dependencies ) + except Exception, e: + error_message = "Error installing tool dependency %s version %s: %s" % ( str( package_name ), str( package_version ), str( e ) ) + log.exception( error_message ) + if tool_dependency: + tool_dependency.status = app.model.ToolDependency.installation_status.ERROR + tool_dependency.error_message = error_message + sa_session.add( tool_dependency ) + sa_session.flush() + if tool_dependency and tool_dependency.status in [ app.model.ToolDependency.installation_status.INSTALLED, + app.model.ToolDependency.installation_status.ERROR ]: + installed_tool_dependencies.append( tool_dependency ) + elif elem.tag == 'set_environment': + env_var_name = env_var_elem.get( 'name', None ) + if env_var_name: + # Tool dependencies of type "set_environmnet" always have the version attribute set to None. + attr_tup = ( env_var_name, None, 'set_environment' ) + if attr_tup in attr_tups_of_dependencies_for_install: try: - tool_dependency = install_package( app, elem, tool_shed_repository, tool_dependencies=tool_dependencies ) + tool_dependency = set_environment( app, elem, tool_shed_repository ) except Exception, e: - error_message = "Error installing tool dependency %s version %s: %s" % ( str( package_name ), str( package_version ), str( e ) ) - log.exception( error_message ) + error_message = "Error setting environment for tool dependency: %s" % str( e ) + log.debug( error_message ) if tool_dependency: tool_dependency.status = app.model.ToolDependency.installation_status.ERROR tool_dependency.error_message = error_message @@ -460,20 +488,6 @@ def handle_tool_dependencies( app, tool_shed_repository, tool_dependencies_confi if tool_dependency and tool_dependency.status in [ app.model.ToolDependency.installation_status.INSTALLED, app.model.ToolDependency.installation_status.ERROR ]: installed_tool_dependencies.append( tool_dependency ) - elif elem.tag == 'set_environment': - try: - tool_dependency = set_environment( app, elem, tool_shed_repository ) - except Exception, e: - error_message = "Error setting environment for tool dependency: %s" % str( e ) - log.debug( error_message ) - if tool_dependency: - tool_dependency.status = app.model.ToolDependency.installation_status.ERROR - tool_dependency.error_message = error_message - sa_session.add( tool_dependency ) - sa_session.flush() - if tool_dependency and tool_dependency.status in [ app.model.ToolDependency.installation_status.INSTALLED, - app.model.ToolDependency.installation_status.ERROR ]: - installed_tool_dependencies.append( tool_dependency ) return installed_tool_dependencies def repository_dependency_needed_only_for_compiling_tool_dependency( repository, repository_dependency ): diff --git a/lib/tool_shed/util/shed_util_common.py b/lib/tool_shed/util/shed_util_common.py index e276955a418..fde3d7cbdf4 100644 --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -144,13 +144,18 @@ def build_repository_ids_select_field( trans, name='repository_ids', multiple=Tr repositories_select_field.add_option( option_label, option_value ) return repositories_select_field -def build_tool_dependencies_select_field( trans, tool_shed_repository, name, multiple=True, display='checkboxes', uninstalled=False ): +def build_tool_dependencies_select_field( trans, tool_shed_repository, name, multiple=True, display='checkboxes', uninstalled_only=False ): """Method called from Galaxy to generate the current list of tool dependency ids for an installed tool shed repository.""" tool_dependencies_select_field = SelectField( name=name, multiple=multiple, display=display ) for tool_dependency in tool_shed_repository.tool_dependencies: - if uninstalled and tool_dependency.status not in [ trans.model.ToolDependency.installation_status.NEVER_INSTALLED, - trans.model.ToolDependency.installation_status.UNINSTALLED ]: - continue + if uninstalled_only: + if tool_dependency.status not in [ trans.model.ToolDependency.installation_status.NEVER_INSTALLED, + trans.model.ToolDependency.installation_status.UNINSTALLED ]: + continue + else: + if tool_dependency.status in [ trans.model.ToolDependency.installation_status.NEVER_INSTALLED, + trans.model.ToolDependency.installation_status.UNINSTALLED ]: + continue option_label = '%s version %s' % ( str( tool_dependency.name ), str( tool_dependency.version ) ) option_value = trans.security.encode_id( tool_dependency.id ) tool_dependencies_select_field.add_option( option_label, option_value )