'Follow the recipe in the received tool_dependencies_config to install specified packages for
repository tools.  The received list of tool_dependencies are the database records for those
dependencies defined in the tool_dependencies_config that are to be installed.  This list may
be a subset of the set of dependencies defined in the tool_dependencies_config.  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.'

def install_specified_tool_dependencies(self, tool_shed_repository, tool_dependencies_config, tool_dependencies, from_tool_migration_manager=False):

    attr_tups_of_dependencies_for_install = [(td.name, td.version, td.type) for td in tool_dependencies]
    installed_packages = []
    tag_manager = TagManager(self.app)
    (tree, error_message) = xml_util.parse_xml(tool_dependencies_config)
    if (tree is None):
        log.debug(('The    received    tool_dependencies.xml    file    is    likely    invalid:    %s' % str(error_message)))
        return installed_packages
    root = tree.getroot()
    elems = []
    for elem in root:
        if (elem.tag == 'set_environment'):
            version = elem.get('version', '1.0')
            if (version != '1.0'):
                raise Exception('The    <set_environment>    tag    must    have    a    version    attribute    with    value    1.0')
            for sub_elem in elem:
                elems.append(sub_elem)
        else:
            elems.append(elem)
    for elem in elems:
        name = elem.get('name', None)
        version = elem.get('version', None)
        type = elem.get('type', None)
        if (type is None):
            if (elem.tag in ['environment_variable', 'set_environment']):
                type = 'set_environment'
            else:
                type = 'package'
        if ((name and (type == 'set_environment')) or (name and version)):
            attr_tup = (name, version, type)
            try:
                index = attr_tups_of_dependencies_for_install.index(attr_tup)
            except ValueError:
                index = None
            if (index is not None):
                tool_dependency = tool_dependencies[index]
                (tool_dependency, proceed_with_install, action_elem_tuples) = tag_manager.process_tag_set(tool_shed_repository, tool_dependency, elem, name, version, from_tool_migration_manager=from_tool_migration_manager, tool_dependency_db_records=tool_dependencies)
                if ((tool_dependency.type == 'package') and proceed_with_install):
                    try:
                        tool_dependency = self.install_package(elem, tool_shed_repository, tool_dependencies=tool_dependencies, from_tool_migration_manager=from_tool_migration_manager)
                    except Exception as e:
                        error_message = ('Error    installing    tool    dependency    %s    version    %s:    %s' % (str(name), str(version), str(e)))
                        log.exception(error_message)
                        if tool_dependency:
                            tool_dependency = tool_dependency_util.set_tool_dependency_attributes(self.app, tool_dependency=tool_dependency, status=self.app.install_model.ToolDependency.installation_status.ERROR, error_message=error_message)
                    if (tool_dependency and (tool_dependency.status in [self.install_model.ToolDependency.installation_status.INSTALLED, self.install_model.ToolDependency.installation_status.ERROR])):
                        installed_packages.append(tool_dependency)
                        if self.app.config.manage_dependency_relationships:
                            self.app.installed_repository_manager.handle_tool_dependency_install(tool_shed_repository, tool_dependency)
    return installed_packages
