commit/galaxy-central: 2 new changesets
2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a46a7f1c3016/ Changeset: a46a7f1c3016 User: jmchilton Date: 2014-11-13 14:19:51+00:00 Summary: Allow resolution of relative paths in tool data configuration and loc files. The string ${__HERE__} will be expanded out to the directory the file (XML configuration or loc) currently resides in. Along with some changes to planemo to detect test data files (https://github.com/galaxyproject/planemo/commit/a40130417dc1be2da785cd5dff64...) - the following picard tweak demonstrates how tool developers could use this to build test cases for cached/index data (https://github.com/jmchilton/picard/commit/4df8974384081ee1bb0f97e1bb8d7f935...). Affected #: 1 file diff -r f26c2543ff053b9ff31617bc03f99d505302ecda -r a46a7f1c3016e3f43a9acabdfb18361679ff723d lib/galaxy/tools/data/__init__.py --- a/lib/galaxy/tools/data/__init__.py +++ b/lib/galaxy/tools/data/__init__.py @@ -10,6 +10,7 @@ import os import os.path import shutil +import string import tempfile from galaxy import util @@ -71,7 +72,7 @@ tree = util.parse_xml( filename ) root = tree.getroot() for table_elem in root.findall( 'table' ): - table = ToolDataTable.from_elem( table_elem, tool_data_path, from_shed_config ) + table = ToolDataTable.from_elem( table_elem, tool_data_path, from_shed_config, filename=filename ) table_elems.append( table_elem ) if table.name not in self.data_tables: self.data_tables[ table.name ] = table @@ -167,16 +168,17 @@ class ToolDataTable( object ): @classmethod - def from_elem( cls, table_elem, tool_data_path, from_shed_config ): + def from_elem( cls, table_elem, tool_data_path, from_shed_config, filename ): table_type = table_elem.get( 'type', 'tabular' ) assert table_type in tool_data_table_types, "Unknown data table type '%s'" % type - return tool_data_table_types[ table_type ]( table_elem, tool_data_path, from_shed_config=from_shed_config ) + return tool_data_table_types[ table_type ]( table_elem, tool_data_path, from_shed_config=from_shed_config, filename=filename ) - def __init__( self, config_element, tool_data_path, from_shed_config = False): + def __init__( self, config_element, tool_data_path, from_shed_config = False, filename=None ): self.name = config_element.get( 'name' ) self.comment_char = config_element.get( 'comment_char' ) self.empty_field_value = config_element.get( 'empty_field_value', '' ) self.empty_field_values = {} + self.here = filename and os.path.dirname(filename) self.filenames = odict() self.tool_data_path = tool_data_path self.missing_index_file = None @@ -241,8 +243,8 @@ type_key = 'tabular' - def __init__( self, config_element, tool_data_path, from_shed_config = False): - super( TabularToolDataTable, self ).__init__( config_element, tool_data_path, from_shed_config) + def __init__( self, config_element, tool_data_path, from_shed_config = False, filename=None ): + super( TabularToolDataTable, self ).__init__( config_element, tool_data_path, from_shed_config, filename) self.config_element = config_element self.data = [] self.configure_and_load( config_element, tool_data_path, from_shed_config) @@ -265,7 +267,7 @@ repo_info = None # Read every file for file_element in config_element.findall( 'file' ): - filename = file_path = file_element.get( 'path', None ) + filename = file_path = expand_here_template( file_element.get( 'path', None ), here=self.here ) found = False if file_path is None: log.debug( "Encountered a file element (%s) that does not contain a path value when loading tool data table '%s'.", util.xml_to_string( file_element ), self.name ) @@ -300,7 +302,7 @@ errors = [] if found: - self.data.extend( self.parse_file_fields( open( filename ), errors=errors ) ) + self.extend_data_with( filename, errors=errors ) self._update_version() else: self.missing_index_file = filename @@ -326,7 +328,7 @@ def handle_found_index_file( self, filename ): self.missing_index_file = None - self.data.extend( self.parse_file_fields( open( filename ) ) ) + self.extend_data_with( filename ) def get_fields( self ): return self.data @@ -380,7 +382,11 @@ if 'name' not in self.columns: self.columns['name'] = self.columns['value'] - def parse_file_fields( self, reader, errors=None ): + def extend_data_with( self, filename, errors=None ): + here = os.path.dirname(os.path.abspath(filename)) + self.data.extend( self.parse_file_fields( open( filename ), errors=errors, here=here ) ) + + def parse_file_fields( self, reader, errors=None, here="__HERE__" ): """ Parse separated lines from file and return a list of tuples. @@ -394,6 +400,7 @@ continue line = line.rstrip( "\n\r" ) if line: + line = expand_here_template( line, here=here ) fields = line.split( self.separator ) if self.largest_index < len( fields ): rval.append( fields ) @@ -529,5 +536,12 @@ rval['fields'] = self.get_fields() return rval + +def expand_here_template(content, here=None): + if here and content: + content = string.Template(content).safe_substitute( { "__HERE__": here }) + return content + + # Registry of tool data types by type_key tool_data_table_types = dict( [ ( cls.type_key, cls ) for cls in [ TabularToolDataTable ] ] ) https://bitbucket.org/galaxy/galaxy-central/commits/782815ce0a91/ Changeset: 782815ce0a91 User: jmchilton Date: 2014-11-18 15:40:21+00:00 Summary: Merged in jmchilton/galaxy-central-fork-1 (pull request #559) Configuration enhancements aim at enabling tool testing of cached data. Affected #: 1 file diff -r e47c67efeda7fa66f9782aae5e2c62ab640310bc -r 782815ce0a91fb69e82ba73cf811e3487b649d56 lib/galaxy/tools/data/__init__.py --- a/lib/galaxy/tools/data/__init__.py +++ b/lib/galaxy/tools/data/__init__.py @@ -10,6 +10,7 @@ import os import os.path import shutil +import string import tempfile from galaxy import util @@ -71,7 +72,7 @@ tree = util.parse_xml( filename ) root = tree.getroot() for table_elem in root.findall( 'table' ): - table = ToolDataTable.from_elem( table_elem, tool_data_path, from_shed_config ) + table = ToolDataTable.from_elem( table_elem, tool_data_path, from_shed_config, filename=filename ) table_elems.append( table_elem ) if table.name not in self.data_tables: self.data_tables[ table.name ] = table @@ -167,16 +168,17 @@ class ToolDataTable( object ): @classmethod - def from_elem( cls, table_elem, tool_data_path, from_shed_config ): + def from_elem( cls, table_elem, tool_data_path, from_shed_config, filename ): table_type = table_elem.get( 'type', 'tabular' ) assert table_type in tool_data_table_types, "Unknown data table type '%s'" % type - return tool_data_table_types[ table_type ]( table_elem, tool_data_path, from_shed_config=from_shed_config ) + return tool_data_table_types[ table_type ]( table_elem, tool_data_path, from_shed_config=from_shed_config, filename=filename ) - def __init__( self, config_element, tool_data_path, from_shed_config = False): + def __init__( self, config_element, tool_data_path, from_shed_config = False, filename=None ): self.name = config_element.get( 'name' ) self.comment_char = config_element.get( 'comment_char' ) self.empty_field_value = config_element.get( 'empty_field_value', '' ) self.empty_field_values = {} + self.here = filename and os.path.dirname(filename) self.filenames = odict() self.tool_data_path = tool_data_path self.missing_index_file = None @@ -241,8 +243,8 @@ type_key = 'tabular' - def __init__( self, config_element, tool_data_path, from_shed_config = False): - super( TabularToolDataTable, self ).__init__( config_element, tool_data_path, from_shed_config) + def __init__( self, config_element, tool_data_path, from_shed_config = False, filename=None ): + super( TabularToolDataTable, self ).__init__( config_element, tool_data_path, from_shed_config, filename) self.config_element = config_element self.data = [] self.configure_and_load( config_element, tool_data_path, from_shed_config) @@ -265,7 +267,7 @@ repo_info = None # Read every file for file_element in config_element.findall( 'file' ): - filename = file_path = file_element.get( 'path', None ) + filename = file_path = expand_here_template( file_element.get( 'path', None ), here=self.here ) found = False if file_path is None: log.debug( "Encountered a file element (%s) that does not contain a path value when loading tool data table '%s'.", util.xml_to_string( file_element ), self.name ) @@ -300,7 +302,7 @@ errors = [] if found: - self.data.extend( self.parse_file_fields( open( filename ), errors=errors ) ) + self.extend_data_with( filename, errors=errors ) self._update_version() else: self.missing_index_file = filename @@ -326,7 +328,7 @@ def handle_found_index_file( self, filename ): self.missing_index_file = None - self.data.extend( self.parse_file_fields( open( filename ) ) ) + self.extend_data_with( filename ) def get_fields( self ): return self.data @@ -380,7 +382,11 @@ if 'name' not in self.columns: self.columns['name'] = self.columns['value'] - def parse_file_fields( self, reader, errors=None ): + def extend_data_with( self, filename, errors=None ): + here = os.path.dirname(os.path.abspath(filename)) + self.data.extend( self.parse_file_fields( open( filename ), errors=errors, here=here ) ) + + def parse_file_fields( self, reader, errors=None, here="__HERE__" ): """ Parse separated lines from file and return a list of tuples. @@ -394,6 +400,7 @@ continue line = line.rstrip( "\n\r" ) if line: + line = expand_here_template( line, here=here ) fields = line.split( self.separator ) if self.largest_index < len( fields ): rval.append( fields ) @@ -529,5 +536,12 @@ rval['fields'] = self.get_fields() return rval + +def expand_here_template(content, here=None): + if here and content: + content = string.Template(content).safe_substitute( { "__HERE__": here }) + return content + + # Registry of tool data types by type_key tool_data_table_types = dict( [ ( cls.type_key, cls ) for cls in [ TabularToolDataTable ] ] ) 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.
participants (1)
-
commits-noreply@bitbucket.org