From 1f6ee2fa8f7ad18d36009e68fbb04790ebc6ed46 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 24 Mar 2015 19:55:01 -0400 Subject: [PATCH] Refactor collection test def objects out of galaxy.tools. Part of ongoing effort to isolate the galaxy.tools.parser and not have it depend on things in galaxy.tools outside that module. --- lib/galaxy/tools/__init__.py | 36 ------------------- lib/galaxy/tools/parser/interface.py | 38 ++++++++++++++++++++ lib/galaxy/tools/parser/xml.py | 6 ++-- lib/tool_shed/metadata/metadata_generator.py | 2 +- test/base/interactor.py | 2 +- 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index d361fdd1354..5b7b0f16b7a 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -2989,42 +2989,6 @@ class BadValue( object ): self.value = value -class TestCollectionDef( object ): - - def __init__( self, elem, parse_param_elem ): - self.elements = [] - attrib = dict( elem.attrib ) - self.collection_type = attrib[ "type" ] - self.name = attrib.get( "name", "Unnamed Collection" ) - for element in elem.findall( "element" ): - element_attrib = dict( element.attrib ) - element_identifier = element_attrib[ "name" ] - nested_collection_elem = element.find( "collection" ) - if nested_collection_elem is not None: - self.elements.append( ( element_identifier, TestCollectionDef( nested_collection_elem, parse_param_elem ) ) ) - else: - self.elements.append( ( element_identifier, parse_param_elem( element ) ) ) - - def collect_inputs( self ): - inputs = [] - for element in self.elements: - value = element[ 1 ] - if isinstance( value, TestCollectionDef ): - inputs.extend( value.collect_inputs() ) - else: - inputs.append( value ) - return inputs - - -class TestCollectionOutputDef( object ): - - def __init__( self, name, attrib, element_tests ): - self.name = name - self.collection_type = attrib.get( "type", None ) - self.attrib = attrib - self.element_tests = element_tests - - def json_fix( val ): if isinstance( val, list ): return [ json_fix( v ) for v in val ] diff --git a/lib/galaxy/tools/parser/interface.py b/lib/galaxy/tools/parser/interface.py index 5f7bc17a6e4..e5b50ebc797 100644 --- a/lib/galaxy/tools/parser/interface.py +++ b/lib/galaxy/tools/parser/interface.py @@ -280,3 +280,41 @@ class ToolStdioExitCode( object ): # TODO: Define a common class or constant for error level: self.error_level = "fatal" self.desc = "" + + +class TestCollectionDef( object ): + # TODO: do not require XML directly here. + + def __init__( self, elem, parse_param_elem ): + self.elements = [] + attrib = dict( elem.attrib ) + self.collection_type = attrib[ "type" ] + self.name = attrib.get( "name", "Unnamed Collection" ) + for element in elem.findall( "element" ): + element_attrib = dict( element.attrib ) + element_identifier = element_attrib[ "name" ] + nested_collection_elem = element.find( "collection" ) + if nested_collection_elem is not None: + self.elements.append( ( element_identifier, TestCollectionDef( nested_collection_elem, parse_param_elem ) ) ) + else: + self.elements.append( ( element_identifier, parse_param_elem( element ) ) ) + + def collect_inputs( self ): + inputs = [] + for element in self.elements: + value = element[ 1 ] + if isinstance( value, TestCollectionDef ): + inputs.extend( value.collect_inputs() ) + else: + inputs.append( value ) + return inputs + + +class TestCollectionOutputDef( object ): + # TODO: do not require XML directly here. + + def __init__( self, name, attrib, element_tests ): + self.name = name + self.collection_type = attrib.get( "type", None ) + self.attrib = attrib + self.element_tests = element_tests diff --git a/lib/galaxy/tools/parser/xml.py b/lib/galaxy/tools/parser/xml.py index 7dd770214f9..e2bbb609bcf 100644 --- a/lib/galaxy/tools/parser/xml.py +++ b/lib/galaxy/tools/parser/xml.py @@ -12,6 +12,8 @@ from .interface import ( InputSource, ToolStdioExitCode, ToolStdioRegex, + TestCollectionDef, + TestCollectionOutputDef, ) from galaxy.util import string_as_bool, xml_text, xml_to_string from galaxy.util.odict import odict @@ -321,7 +323,7 @@ def __parse_output_collection_elem( output_collection_elem ): if identifier is None: raise Exception( "Test primary dataset does not have a 'identifier'" ) element_tests[ identifier ] = __parse_test_attributes( element, element_attrib ) - return galaxy.tools.TestCollectionOutputDef( name, attrib, element_tests ) + return TestCollectionOutputDef( name, attrib, element_tests ) def __parse_test_attributes( output_elem, attrib ): @@ -486,7 +488,7 @@ def __parse_param_elem( param_elem, i=0 ): elif child.tag == 'edit_attributes': attrib['edit_attributes'].append( child ) elif child.tag == 'collection': - attrib[ 'collection' ] = galaxy.tools.TestCollectionDef( child, __parse_param_elem ) + attrib[ 'collection' ] = TestCollectionDef( child, __parse_param_elem ) if composite_data_name: # Composite datasets need implicit renaming; # inserted at front of list so explicit declarations diff --git a/lib/tool_shed/metadata/metadata_generator.py b/lib/tool_shed/metadata/metadata_generator.py index 079f4e11adc..041044ae46a 100644 --- a/lib/tool_shed/metadata/metadata_generator.py +++ b/lib/tool_shed/metadata/metadata_generator.py @@ -7,7 +7,7 @@ from galaxy import util from galaxy.datatypes import checkers from galaxy.model.orm import and_ from galaxy.tools.data_manager.manager import DataManager -from galaxy.tools import TestCollectionDef +from galaxy.tools.parser.interface import TestCollectionDef from galaxy.web import url_for from tool_shed.repository_types import util as rt_util diff --git a/test/base/interactor.py b/test/base/interactor.py index 97886a98129..b70bf4fc5d4 100644 --- a/test/base/interactor.py +++ b/test/base/interactor.py @@ -1,7 +1,7 @@ import os import re from StringIO import StringIO -from galaxy.tools import TestCollectionDef +from galaxy.tools.parser.interface import TestCollectionDef from galaxy import eggs eggs.require( "requests" ) from galaxy import util