3 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/f7b777f46f9b/ Changeset: f7b777f46f9b User: jmchilton Date: 2014-12-26 14:55:27+00:00 Summary: Remove unused method lib/galaxy/workflow/modules.py. Affected #: 1 file diff -r 4844fa1099447fb8397159be710c99a82726821a -r f7b777f46f9b69b3cd2ca2d90a30988d9f4fa0ab lib/galaxy/workflow/modules.py --- a/lib/galaxy/workflow/modules.py +++ b/lib/galaxy/workflow/modules.py @@ -557,13 +557,6 @@ def normalize_runtime_state( self, runtime_state ): return runtime_state.encode( self.tool, self.trans.app, secure=False ) - @classmethod - def __get_tool_version( cls, trans, tool_id ): - # Return a ToolVersion if one exists for tool_id. - return trans.install_model.context.query( trans.install_model.ToolVersion ) \ - .filter( trans.install_model.ToolVersion.table.c.tool_id == tool_id ) \ - .first() - def save_to_step( self, step ): step.type = self.type step.tool_id = self.tool_id https://bitbucket.org/galaxy/galaxy-central/commits/8a2b4ebdf492/ Changeset: 8a2b4ebdf492 User: jmchilton Date: 2014-12-26 14:55:27+00:00 Summary: Eliminate direct in/get checks against toolbox.tools_by_id - use get_tool or has_tool. Affected #: 6 files diff -r f7b777f46f9b69b3cd2ca2d90a30988d9f4fa0ab -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c lib/galaxy/jobs/__init__.py --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -711,7 +711,7 @@ self.job_id = job.id self.session_id = job.session_id self.user_id = job.user_id - self.tool = queue.app.toolbox.tools_by_id.get( job.tool_id, None ) + self.tool = queue.app.toolbox.get_tool( job.tool_id, exact=True ) self.queue = queue self.app = queue.app self.sa_session = self.app.model.context diff -r f7b777f46f9b69b3cd2ca2d90a30988d9f4fa0ab -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c lib/galaxy/jobs/handler.py --- a/lib/galaxy/jobs/handler.py +++ b/lib/galaxy/jobs/handler.py @@ -119,7 +119,7 @@ & ( model.Job.handler == self.app.config.server_name ) ).all() for job in jobs_at_startup: - if job.tool_id not in self.app.toolbox.tools_by_id: + if not self.app.toolbox.has_tool( job.tool_id, exact=True ): log.warning( "(%s) Tool '%s' removed from tool config, unable to recover job" % ( job.id, job.tool_id ) ) self.job_wrapper( job ).fail( 'This tool was disabled before the job completed. Please contact your Galaxy administrator.' ) elif job.job_runner_name is not None and job.job_runner_external_id is None: diff -r f7b777f46f9b69b3cd2ca2d90a30988d9f4fa0ab -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c lib/galaxy/managers/workflows.py --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -224,7 +224,7 @@ errors = [] for key, step_dict in data['steps'].iteritems(): is_tool = is_tool_module_type( step_dict[ 'type' ] ) - if is_tool and step_dict['tool_id'] not in trans.app.toolbox.tools_by_id: + if is_tool and not trans.app.toolbox.has_tool( step_dict['tool_id'], exact=True ): errors.append("Step %s requires tool '%s'." % (step_dict['id'], step_dict['tool_id'])) if errors: raise MissingToolsException(workflow, errors) diff -r f7b777f46f9b69b3cd2ca2d90a30988d9f4fa0ab -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -478,8 +478,11 @@ shutil.move( filename, os.path.abspath( self.integrated_tool_panel_config ) ) os.chmod( self.integrated_tool_panel_config, 0644 ) - def get_tool( self, tool_id, tool_version=None, get_all_versions=False ): + def get_tool( self, tool_id, tool_version=None, get_all_versions=False, exact=False ): """Attempt to locate a tool in the tool box.""" + if get_all_versions and exact: + raise AssertionError("Cannot specify get_tool with both get_all_versions and exact as True") + if tool_id in self.tools_by_id and not get_all_versions: #tool_id exactly matches an available tool by id (which is 'old' tool_id or guid) return self.tools_by_id[ tool_id ] @@ -513,6 +516,9 @@ return[ self.tools_by_id[ tool_id ] ] return None + def has_tool( self, tool_id, exact=False ): + return self.get_tool( tool_id, exact=exact ) is not None + def get_loaded_tools_by_lineage( self, tool_id ): """Get all loaded tools associated by lineage to the tool whose id is tool_id.""" tv = self.__get_tool_version( tool_id ) diff -r f7b777f46f9b69b3cd2ca2d90a30988d9f4fa0ab -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c lib/galaxy/webapps/galaxy/controllers/admin.py --- a/lib/galaxy/webapps/galaxy/controllers/admin.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin.py @@ -486,7 +486,8 @@ class ToolIdColumn( grids.TextColumn ): def get_value( self, trans, grid, tool_version ): - if tool_version.tool_id in trans.app.toolbox.tools_by_id: + toolbox = trans.app.toolbox + if toolbox.has_tool( tool_version.tool_id, exact=True ): link = url_for( controller='tool_runner', tool_id=tool_version.tool_id ) link_str = '<a href="%s">' % link return '<div class="count-box state-color-ok">%s%s</a></div>' % ( link_str, tool_version.tool_id ) @@ -497,8 +498,9 @@ def get_value( self, trans, grid, tool_version ): tool_ids_str = '' + toolbox = trans.app.toolbox for tool_id in tool_version.get_version_ids( trans.app ): - if tool_id in trans.app.toolbox.tools_by_id: + if toolbox.has_tool( tool_id, exact=True ): link = url_for( controller='tool_runner', tool_id=tool_version.tool_id ) link_str = '<a href="%s">' % link tool_ids_str += '<div class="count-box state-color-ok">%s%s</a></div><br/>' % ( link_str, tool_id ) diff -r f7b777f46f9b69b3cd2ca2d90a30988d9f4fa0ab -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c test/unit/jobs/test_job_wrapper.py --- a/test/unit/jobs/test_job_wrapper.py +++ b/test/unit/jobs/test_job_wrapper.py @@ -190,14 +190,14 @@ def __init__(self, test_tool): self.test_tool = test_tool - @property - def tools_by_id(self): - return self - def get(self, tool_id, default=None): assert tool_id == TEST_TOOL_ID return self.test_tool + def get_tool( self, tool_id, exact=False ): + tool = self.get(tool_id) + return tool + class MockObjectStore(object): https://bitbucket.org/galaxy/galaxy-central/commits/338a32cc6067/ Changeset: 338a32cc6067 User: jmchilton Date: 2014-12-26 14:55:27+00:00 Summary: Introduce abstraction shielding toolbox.tools_by_id from galaxy.workflow.modules. That was the last module outside of ToolBox itself that was accessing tools_by_id directly. Affected #: 5 files diff -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c -r 338a32cc6067d92055324e4b827697051ec99254 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -519,6 +519,21 @@ def has_tool( self, tool_id, exact=False ): return self.get_tool( tool_id, exact=exact ) is not None + def get_tool_id( self, tool_id ): + """ Take a tool id (potentially from a different Galaxy instance or that + is no longer loaded - and find the closest match to the currently loaded + tools (using get_tool for inexact matches which currently returns the oldest + tool shed installed tool with the same short id). + """ + if tool_id not in self.tools_by_id: + tool = self.get_tool( tool_id ) + if tool: + tool_id = tool.id + else: + tool_id = None + # else exact match - leave unmodified. + return tool_id + def get_loaded_tools_by_lineage( self, tool_id ): """Get all loaded tools associated by lineage to the tool whose id is tool_id.""" tv = self.__get_tool_version( tool_id ) diff -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c -r 338a32cc6067d92055324e4b827697051ec99254 lib/galaxy/workflow/modules.py --- a/lib/galaxy/workflow/modules.py +++ b/lib/galaxy/workflow/modules.py @@ -508,15 +508,13 @@ def from_workflow_step( Class, trans, step ): toolbox = trans.app.toolbox tool_id = step.tool_id - if toolbox and tool_id not in toolbox.tools_by_id: + if toolbox: # See if we have access to a different version of the tool. # TODO: If workflows are ever enhanced to use tool version # in addition to tool id, enhance the selection process here # to retrieve the correct version of the tool. - tool = toolbox.get_tool( tool_id ) - if tool: - tool_id = tool.id - if ( toolbox and tool_id in toolbox.tools_by_id ): + tool_id = toolbox.get_tool_id( tool_id ) + if ( toolbox and tool_id ): if step.config: # This step has its state saved in the config field due to the # tool being previously unavailable. diff -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c -r 338a32cc6067d92055324e4b827697051ec99254 test/unit/tools/test_toolbox.py --- a/test/unit/tools/test_toolbox.py +++ b/test/unit/tools/test_toolbox.py @@ -186,6 +186,15 @@ # No changes, should be regenerated self.assert_integerated_tool_panel(exists=False) + def test_get_tool_id( self ): + self._init_tool() + self._setup_two_versions_in_config( ) + self._setup_two_versions() + assert self.toolbox.get_tool_id( "test_tool" ) == "github.com/galaxyproect/example/test_tool/0.1" + assert self.toolbox.get_tool_id( "github.com/galaxyproect/example/test_tool/0.1" ) == "github.com/galaxyproect/example/test_tool/0.1" + assert self.toolbox.get_tool_id( "github.com/galaxyproect/example/test_tool/0.2" ) == "github.com/galaxyproect/example/test_tool/0.2" + assert self.toolbox.get_tool_id( "github.com/galaxyproect/example/test_tool/0.3" ) is None + def __verify_two_test_tools( self ): # Assert tool versions of the tool with simple id 'test_tool' all_versions = self.toolbox.get_tool( "test_tool", get_all_versions=True ) diff -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c -r 338a32cc6067d92055324e4b827697051ec99254 test/unit/workflows/test_modules.py --- a/test/unit/workflows/test_modules.py +++ b/test/unit/workflows/test_modules.py @@ -5,6 +5,7 @@ import mock from galaxy import model +from galaxy.util import bunch from galaxy.workflow import modules from .workflow_support import MockTrans @@ -201,6 +202,37 @@ assert exception +def test_updated_tool_version(): + trans = MockTrans() + mock_tool = __mock_tool(id="cat1", version="0.9") + trans.app.toolbox.tools[ "cat1" ] = mock_tool + module = __from_step( + trans=trans, + type="tool", + tool_id="cat1", + tool_version="0.7", + config=None, + ) + # Make sure there is a warnin with tool id, old version, + # and new version. + for val in "cat1", "0.7", "0.9": + assert val in module.version_changes[0] + + +def test_tool_version_same(): + trans = MockTrans() + mock_tool = __mock_tool(id="cat1", version="1.0") + trans.app.toolbox.tools[ "cat1" ] = mock_tool + module = __from_step( + trans=trans, + type="tool", + tool_id="cat1", + tool_version="1.0", + config=None, + ) + assert not module.version_changes + + def __assert_has_runtime_input( module, label=None, collection_type=None ): inputs = module.get_runtime_inputs() assert len( inputs ) == 1 @@ -221,7 +253,11 @@ def __from_step( **kwds ): - trans = MockTrans() + if "trans" in kwds: + trans = kwds["trans"] + del kwds["trans"] + else: + trans = MockTrans() step = __step( **kwds ) @@ -238,3 +274,20 @@ setattr( step, key, value ) return step + + +def __mock_tool( + id="cat1", + version="1.0", +): + # For now ignoring inputs, params_from_strings, and + # check_and_update_param_values since only have unit tests for version + # handling - but need to write tests for all of this longer term. + tool = bunch.Bunch( + id=id, + version=version, + inputs={}, + params_from_strings=mock.Mock(), + check_and_update_param_values=mock.Mock(), + ) + return tool diff -r 8a2b4ebdf4927fccbe44eda80eaba17b8033802c -r 338a32cc6067d92055324e4b827697051ec99254 test/unit/workflows/workflow_support.py --- a/test/unit/workflows/workflow_support.py +++ b/test/unit/workflows/workflow_support.py @@ -40,3 +40,7 @@ def get_tool( self, tool_id ): # Real tool box returns None of missing tool also return self.tools.get( tool_id, None ) + + def get_tool_id( self, tool_id ): + tool = self.get_tool( tool_id ) + return tool and tool.id 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.