Fix module resolution for migrated toolbox filters path -- reuses (in a hacky way) the filtering function that was duplicated to galaxy.tools.toolbox.filters. Pushing more of this functionality (the docs, etc) into the FilterFactory might be nice down the road.

This commit is contained in:
Dannon Baker
2016-06-14 14:30:31 -04:00
parent 419594845d
commit 0c4fd995c5
2 changed files with 9 additions and 17 deletions
+2 -2
View File
@@ -55,13 +55,13 @@ class FilterFactory( object ):
def __init_filters( self, key, filters, toolbox_filters, validate=None ):
for filter in filters:
if validate is None or filter in validate or filter in self.default_filters:
filter_function = self.__build_filter_function( filter )
filter_function = self._build_filter_function( filter )
toolbox_filters[ key ].append( filter_function )
else:
log.warning( "Refusing to load %s filter '%s' which is not defined in config", key, filter )
return toolbox_filters
def __build_filter_function( self, filter_name ):
def _build_filter_function( self, filter_name ):
"""Obtain python function (importing a submodule if needed)
corresponding to filter_name.
"""
+7 -15
View File
@@ -22,6 +22,7 @@ from galaxy.security.validate_user_input import (transform_publicname,
validate_email,
validate_password,
validate_publicname)
from galaxy.tools.toolbox.filters import FilterFactory
from galaxy.util import biostar, hash_util, docstring_trim, listify
from galaxy.web import url_for
from galaxy.web.base.controller import (BaseUIController,
@@ -1269,7 +1270,7 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
The user can activate them and the choice is stored in user_preferences.
"""
def get_filter_mapping( db_filters, config_filters ):
def get_filter_mapping( db_filters, config_filters, factory ):
"""
Compare the allowed filters from the galaxy.ini config file with the previously saved or default filters from the database.
We need that to toogle the checkboxes for the formular in the right way.
@@ -1277,17 +1278,7 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
"""
filters = list()
for filter_name in config_filters:
if ":" in filter_name:
# Should be a submodule of filters (e.g. examples:restrict_development_tools)
(module_name, function_name) = filter_name.rsplit(":", 1)
module_name = 'galaxy.tools.filters.%s' % module_name.strip()
module = __import__( module_name, globals(), fromlist=['temp_module'] )
function = getattr( module, function_name.strip() )
else:
# No module found it has to be explicitly imported.
module = __import__( 'galaxy.tools.filters', globals(), fromlist=['temp_module'] )
function = getattr( globals(), filter_name.strip() )
function = factory._build_filter_function(filter_name)
doc_string = docstring_trim( function.__doc__ )
split = doc_string.split('\n\n')
if split:
@@ -1328,9 +1319,10 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
elif name == 'toolbox_label_filters':
saved_user_label_filters = listify( value, do_strip=True )
tool_filters = get_filter_mapping( saved_user_tool_filters, trans.app.config.user_tool_filters )
section_filters = get_filter_mapping( saved_user_section_filters, trans.app.config.user_section_filters )
label_filters = get_filter_mapping( saved_user_label_filters, trans.app.config.user_label_filters )
ff = FilterFactory(trans.app.toolbox)
tool_filters = get_filter_mapping( saved_user_tool_filters, trans.app.config.user_tool_filters, ff )
section_filters = get_filter_mapping( saved_user_section_filters, trans.app.config.user_section_filters, ff )
label_filters = get_filter_mapping( saved_user_label_filters, trans.app.config.user_label_filters, ff )
return trans.fill_template( 'user/toolbox_filters.mako',
cntrller=cntrller,