1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/41bb60076082/ Changeset: 41bb60076082 User: devteam Date: 2014-05-02 21:55:45 Summary: Enhance the framework that supports discovery of tool dependencies' scripts that are in the same repository as the tool. This eliminates the requirement for setting a variable _SCRIPT_PATH in the tool_dependencies.xml and requirements tagset in a tool config. Now it only needs to be set in the tool config and it should look like: <requirement type="set_environment">PATH</requirement> Affected #: 5 files
diff -r 2f79c07c4438b627df03aa3f96dcd51f8b12c641 -r 41bb60076082ea46686a4bb9db8cb593b8f35851 lib/tool_shed/galaxy_install/tool_dependencies/install_util.py --- a/lib/tool_shed/galaxy_install/tool_dependencies/install_util.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/install_util.py @@ -289,6 +289,55 @@ raise Exception( message ) return handled_tool_dependencies
+def handle_env_vars_for_set_environment_tool_dependency( app, tool_shed_repository, tool_shed_repository_install_dir ): + env_var_name = 'PATH' + install_dir = \ + tool_dependency_util.get_tool_dependency_install_dir( app=app, + repository_name=tool_shed_repository.name, + repository_owner=tool_shed_repository.owner, + repository_changeset_revision=tool_shed_repository.installed_changeset_revision, + tool_dependency_type='set_environment', + tool_dependency_name=env_var_name, + tool_dependency_version=None ) + env_var_dict = dict( name=env_var_name, action='prepend_to', value=tool_shed_repository_install_dir ) + if not os.path.exists( install_dir ): + os.makedirs( install_dir ) + status = app.install_model.ToolDependency.installation_status.INSTALLING + tool_dependency = \ + tool_dependency_util.create_or_update_tool_dependency( app=app, + tool_shed_repository=tool_shed_repository, + name=env_var_name, + version=None, + type='set_environment', + status=status, + set_status=True ) + env_file_builder = EnvFileBuilder( install_dir ) + return_code = env_file_builder.append_line( make_executable=True, **env_var_dict ) + if return_code: + error_message = 'Error creating env.sh file for tool dependency %s, return_code: %s' % \ + ( str( tool_dependency.name ), str( return_code ) ) + log.debug( error_message ) + status = app.install_model.ToolDependency.installation_status.ERROR + tool_dependency = \ + tool_dependency_util.set_tool_dependency_attributes( app, + tool_dependency=tool_dependency, + status=status, + error_message=error_message, + remove_from_disk=False ) + else: + if tool_dependency.status not in [ app.install_model.ToolDependency.installation_status.ERROR, + app.install_model.ToolDependency.installation_status.INSTALLED ]: + status = app.install_model.ToolDependency.installation_status.INSTALLED + tool_dependency = \ + tool_dependency_util.set_tool_dependency_attributes( app, + tool_dependency=tool_dependency, + status=status, + error_message=None, + remove_from_disk=False ) + log.debug( 'Environment variable %s set in %s for tool dependency %s.' % \ + ( str( env_var_name ), str( install_dir ), str( tool_dependency.name ) ) ) + return tool_dependency + def install_and_build_package_via_fabric( app, tool_shed_repository, tool_dependency, actions_dict ): sa_session = app.install_model.context try: @@ -638,12 +687,20 @@ """ # TODO: Add support for a repository dependency definition within this tool dependency type's tag set. This should look something like # the following. See the implementation of support for this in the tool dependency package type's method above. + # This function is only called for set environment actions as defined below, not within an <install version="1.0"> tool + # dependency type. Here is an example of the tag set this function does handle: + # <action type="set_environment"> + # <environment_variable name="PATH" action="prepend_to">$INSTALL_DIR</environment_variable> + # </action> + # Here is an example of the tag set this function does not handle: # <set_environment version="1.0"> # <repository toolshed="<tool shed>" name="<repository name>" owner="<repository owner>" changeset_revision="<changeset revision>" /> # </set_environment> sa_session = app.install_model.context - tool_dependency = None + tool_dependencies = [] env_var_version = elem.get( 'version', '1.0' ) + tool_shed_repository_install_dir = fabric_util.get_tool_shed_repository_install_dir( app, tool_shed_repository ) + tool_shed_repository_install_dir_added_to_path = False for env_var_elem in elem: # Althoug we're in a loop here, this method will always return only a single ToolDependency or None. env_var_name = env_var_elem.get( 'name', None ) @@ -662,10 +719,10 @@ tool_dependency_type='set_environment', tool_dependency_name=env_var_name, tool_dependency_version=None ) - tool_shed_repository_install_dir = fabric_util.get_tool_shed_repository_install_dir( app, tool_shed_repository ) + install_environment = InstallEnvironment( tool_shed_repository_install_dir=tool_shed_repository_install_dir, + install_dir=install_dir ) env_var_dict = td_common_util.create_env_var_dict( elem=env_var_elem, - tool_dependency_install_dir=install_dir, - tool_shed_repository_install_dir=tool_shed_repository_install_dir ) + install_environment=install_environment ) if env_var_dict: if not os.path.exists( install_dir ): os.makedirs( install_dir ) @@ -714,7 +771,18 @@ status=status, error_message=error_message, remove_from_disk=False ) - return tool_dependency + if tool_dependency.status != app.install_model.ToolDependency.installation_status.ERROR: + if env_var_dict[ 'name' ] == 'PATH' and \ + env_var_dict[ 'action' ] in [ 'prepend_to', 'set_to', 'append_to' ] and \ + env_var_dict[ 'value' ] == install_environment.tool_shed_repository_install_dir: + tool_shed_repository_install_dir_added_to_path = True + tool_dependencies.append( tool_dependency ) + if not tool_shed_repository_install_dir_added_to_path: + tool_dependency = handle_env_vars_for_set_environment_tool_dependency( app, + tool_shed_repository, + tool_shed_repository_install_dir ) + tool_dependencies.append( tool_dependency ) + return tool_dependencies
def strip_path( fpath ): if not fpath:
diff -r 2f79c07c4438b627df03aa3f96dcd51f8b12c641 -r 41bb60076082ea46686a4bb9db8cb593b8f35851 lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py --- a/lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py @@ -707,17 +707,22 @@ return env_var_dict
def prepare_step( self, app, tool_dependency, action_elem, action_dict, install_environment, is_binary_download ): + # This function is only called for set environment actions as defined above, not within a <set_environment> tool + # dependency type. Here is an example of the tag set this function does handle: # <action type="set_environment"> # <environment_variable name="PYTHONPATH" action="append_to">$INSTALL_DIR/lib/python</environment_variable> # <environment_variable name="PATH" action="prepend_to">$INSTALL_DIR/bin</environment_variable> # </action> + # Here is an example of the tag set this function does not handle: + # <action type="set_environment"> + # <environment_variable name="PATH" action="prepend_to">$INSTALL_DIR</environment_variable> + # </action> env_var_dicts = [] for env_elem in action_elem: if env_elem.tag == 'environment_variable': env_var_dict = \ td_common_util.create_env_var_dict( elem=env_elem, - tool_dependency_install_dir=install_environment.install_dir, - tool_shed_repository_install_dir=install_environment.tool_shed_repository_install_dir ) + install_environment=install_environment ) if env_var_dict: env_var_dicts.append( env_var_dict ) if env_var_dicts:
diff -r 2f79c07c4438b627df03aa3f96dcd51f8b12c641 -r 41bb60076082ea46686a4bb9db8cb593b8f35851 lib/tool_shed/galaxy_install/tool_dependencies/td_common_util.py --- a/lib/tool_shed/galaxy_install/tool_dependencies/td_common_util.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/td_common_util.py @@ -168,10 +168,12 @@ return True return False
-def create_env_var_dict( elem, tool_dependency_install_dir=None, tool_shed_repository_install_dir=None ): +def create_env_var_dict( elem, install_environment ): env_var_name = elem.get( 'name', 'PATH' ) env_var_action = elem.get( 'action', 'prepend_to' ) env_var_text = None + tool_dependency_install_dir = install_environment.install_dir + tool_shed_repository_install_dir = install_environment.tool_shed_repository_install_dir if elem.text and elem.text.find( 'REPOSITORY_INSTALL_DIR' ) >= 0: if tool_shed_repository_install_dir and elem.text.find( '$REPOSITORY_INSTALL_DIR' ) != -1: env_var_text = elem.text.replace( '$REPOSITORY_INSTALL_DIR', tool_shed_repository_install_dir )
diff -r 2f79c07c4438b627df03aa3f96dcd51f8b12c641 -r 41bb60076082ea46686a4bb9db8cb593b8f35851 lib/tool_shed/util/common_install_util.py --- a/lib/tool_shed/util/common_install_util.py +++ b/lib/tool_shed/util/common_install_util.py @@ -349,9 +349,15 @@ requirement_dict[ 'status' ] = tool_dependency_status new_val.append( requirement_dict ) if tool_dependency_status in [ trans.install_model.ToolDependency.installation_status.INSTALLED ]: - installed_tool_dependencies[ td_key ] = new_val + if td_key in installed_tool_dependencies: + installed_tool_dependencies[ td_key ].extend( new_val ) + else: + installed_tool_dependencies[ td_key ] = new_val else: - missing_tool_dependencies[ td_key ] = new_val + if td_key in missing_tool_dependencies: + missing_tool_dependencies[ td_key ].extend( new_val ) + else: + missing_tool_dependencies[ td_key ] = new_val else: # The val dictionary looks something like this: # {'repository_name': 'xx', @@ -497,6 +503,7 @@ return installed_tool_dependencies root = tree.getroot() fabric_version_checked = False + set_environment_handled = False for elem in root: if elem.tag == 'package': # Only install the tool_dependency if it is not already installed and it is associated with a database record in the received @@ -556,21 +563,31 @@ # <set_environment version="1.0"> # <environment_variable name="R_SCRIPT_PATH"action="set_to">$REPOSITORY_INSTALL_DIR</environment_variable> # </set_environment> + set_environment_handled = True try: - tool_dependency = set_environment( app, elem, tool_shed_repository, attr_tups_of_dependencies_for_install ) + tool_dependencies = set_environment( app, elem, tool_shed_repository, attr_tups_of_dependencies_for_install ) except Exception, e: error_message = "Error setting environment for tool dependency: %s" % str( e ) log.debug( error_message ) - if tool_dependency: - # Since there was an installation error, update the tool dependency status to Error. The remove_installation_path option must - # be left False here. - tool_dependency = tool_dependency_util.handle_tool_dependency_installation_error( app, - tool_dependency, - error_message, - remove_installation_path=False ) - if tool_dependency and tool_dependency.status in [ app.install_model.ToolDependency.installation_status.INSTALLED, - app.install_model.ToolDependency.installation_status.ERROR ]: - installed_tool_dependencies.append( tool_dependency ) + for tool_dependency in tool_dependencies: + if tool_dependency and tool_dependency.status == app.install_model.ToolDependency.installation_status.ERROR: + # Since there was an installation error, update the tool dependency status to Error. The remove_installation_path option must + # be left False here. + tool_dependency = tool_dependency_util.handle_tool_dependency_installation_error( app, + tool_dependency, + error_message, + remove_installation_path=False ) + for tool_dependency in tool_dependencies: + if tool_dependency and tool_dependency.status in [ app.install_model.ToolDependency.installation_status.INSTALLED, + app.install_model.ToolDependency.installation_status.ERROR ]: + installed_tool_dependencies.append( tool_dependency ) + if not set_environment_handled: + element_attributes = dict( name='PATH', action='prepend_to' ) + generated_elem = xml_util.create_element( 'environment_variable', attributes=element_attributes, sub_elements=None ) + generated_elem.text = '$REPOSITORY_INSTALL_DIR' + generated_attr_tups = [ ( 'PATH', None, 'set_environment' ) ] + tool_dependencies = set_environment( app, generated_elem, tool_shed_repository, generated_attr_tups ) + installed_tool_dependencies.extend( tool_dependencies ) return installed_tool_dependencies
def repository_dependency_needed_only_for_compiling_tool_dependency( repository, repository_dependency ):
diff -r 2f79c07c4438b627df03aa3f96dcd51f8b12c641 -r 41bb60076082ea46686a4bb9db8cb593b8f35851 lib/tool_shed/util/metadata_util.py --- a/lib/tool_shed/util/metadata_util.py +++ b/lib/tool_shed/util/metadata_util.py @@ -23,6 +23,7 @@ from tool_shed.galaxy_install.tool_dependencies import install_util from tool_shed.galaxy_install.tool_dependencies import td_common_util import tool_shed.repository_types.util as rt_util +from xml.etree import ElementTree as XmlET
eggs.require( 'mercurial' )
@@ -921,7 +922,28 @@ invalid_tool_dependencies_dict = {} valid_repository_dependency_tups = [] invalid_repository_dependency_tups = [] + needs_set_environment_tool_dependency_for_path = False + tools_metadata = metadata_dict.get( 'tools', None ) + if tools_metadata is not None: + for tools_dict in tools_metadata: + requirements = tools_dict.get( 'requirements', None ) + if requirements is not None: + for requirements_dict in requirements: + if requirements_dict[ 'type' ] == 'set_environment' and requirements_dict[ 'name' ] == 'PATH': + needs_set_environment_tool_dependency_for_path = True + break description = root.get( 'description' ) + if needs_set_environment_tool_dependency_for_path: + # Add this to the in-memory XML tree that is parsed to determine the database tool dependency records. This will not + # modify the on-disk tool dependency definitions, but is needed in order for the tool to correctly source the env.sh + # file that was generated for the PATH variable. + # <set_environment version="1.0"> + # <environment_variable action="prepend_to" name="PATH">$REPOSITORY_INSTALL_DIR</environment_variable> + # </set_environment> + env_var_elem_attributes = dict( name='PATH', action='prepend_to' ) + set_environment_elem = xml_util.create_element( 'set_environment', attributes=dict( version='1.0' ) ) + XmlET.SubElement( set_environment_elem, 'environment_variable', attrib=env_var_elem_attributes ) + root.append( set_environment_elem ) for elem in root: if elem.tag == 'package': valid_tool_dependencies_dict, invalid_tool_dependencies_dict, repository_dependency_tup, repository_dependency_is_valid, message = \
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
galaxy-commits@lists.galaxyproject.org