6 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/50062f6e9b47/ Changeset: 50062f6e9b47 User: jmchilton Date: 2014-12-28 16:23:44+00:00 Summary: PEP-8 fixes for a few Tool Shed install components. - lib/tool_shed/galaxy_install/install_manager.py - lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py - lib/tool_shed/galaxy_install/repair_repository_manager.py Affected #: 3 files diff -r 97f46da40bb3767c6cf0d440b1d2d58e06edf5e6 -r 50062f6e9b47a36dad57393292611632908fe79a lib/tool_shed/galaxy_install/install_manager.py --- a/lib/tool_shed/galaxy_install/install_manager.py +++ b/lib/tool_shed/galaxy_install/install_manager.py @@ -42,11 +42,11 @@ class InstallToolDependencyManager( object ): - + def __init__( self, app ): self.app = app self.install_model = self.app.install_model - self.INSTALL_ACTIONS = [ 'download_binary', 'download_by_url', 'download_file', + self.INSTALL_ACTIONS = [ 'download_binary', 'download_by_url', 'download_file', 'setup_perl_environment', 'setup_python_environment', 'setup_r_environment', 'setup_ruby_environment', 'shell_command' ] @@ -142,9 +142,9 @@ # Since there was an installation error, update the tool dependency status to Error. The remove_installation_path option must # be left False here. error_message = '%s\n%s' % ( self.format_traceback(), str( e ) ) - tool_dependency = tool_dependency_util.handle_tool_dependency_installation_error( self.app, - tool_dependency, - error_message, + tool_dependency = tool_dependency_util.handle_tool_dependency_installation_error( self.app, + tool_dependency, + error_message, remove_installation_path=False ) tool_dependency = self.mark_tool_dependency_installed( tool_dependency ) return tool_dependency @@ -208,9 +208,9 @@ tool_dependency_db_records=tool_dependencies ) if ( tool_dependency.type == 'package' and proceed_with_install ): try: - tool_dependency = self.install_package( elem, - tool_shed_repository, - tool_dependencies=tool_dependencies, + tool_dependency = self.install_package( elem, + tool_shed_repository, + tool_dependencies=tool_dependencies, from_tool_migration_manager=from_tool_migration_manager ) except Exception, e: error_message = "Error installing tool dependency %s version %s: %s" % \ @@ -220,9 +220,9 @@ # 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( self.app, - tool_dependency, - error_message, + tool_dependency_util.handle_tool_dependency_installation_error( self.app, + tool_dependency, + error_message, remove_installation_path=False ) if tool_dependency and tool_dependency.status in [ self.install_model.ToolDependency.installation_status.INSTALLED, self.install_model.ToolDependency.installation_status.ERROR ]: @@ -236,7 +236,7 @@ def install_via_fabric( self, tool_shed_repository, tool_dependency, install_dir, package_name=None, custom_fabfile_path=None, actions_elem=None, action_elem=None, **kwd ): """ - Parse a tool_dependency.xml file's <actions> tag set to gather information for installation using + Parse a tool_dependency.xml file's <actions> tag set to gather information for installation using self.install_and_build_package(). The use of fabric is being eliminated, so some of these functions may need to be renamed at some point. """ @@ -363,8 +363,8 @@ else: # Process the next matching <actions> tag, or any defined <actions> tags that do not # contain platform dependent recipes. - log.debug( 'Error downloading binary for tool dependency %s version %s: %s' % \ - ( str( package_name ), str( package_version ), str( tool_dependency.error_message ) ) ) + log.debug( 'Error downloading binary for tool dependency %s version %s: %s' % + ( str( package_name ), str( package_version ), str( tool_dependency.error_message ) ) ) else: if actions_elem.tag == 'actions': # We've reached an <actions> tag that defines the recipe for installing and compiling from @@ -380,7 +380,7 @@ if removed: can_install_from_source = True else: - log.debug( 'Error removing old files from installation directory %s: %s' % \ + log.debug( 'Error removing old files from installation directory %s: %s' % ( str( installation_directory, str( error_message ) ) ) ) else: can_install_from_source = True @@ -389,7 +389,7 @@ if can_install_from_source: # We now know that binary installation was not successful, so proceed with the <actions> # tag set that defines the recipe to install and compile from source. - log.debug( 'Proceeding with install and compile recipe for tool dependency %s.' % \ + log.debug( 'Proceeding with install and compile recipe for tool dependency %s.' % str( tool_dependency.name ) ) tool_dependency = self.install_via_fabric( tool_shed_repository, tool_dependency, @@ -398,7 +398,7 @@ actions_elem=actions_elem, action_elem=None ) if actions_elem.tag == 'action' and \ - tool_dependency.status != self.install_model.ToolDependency.installation_status.ERROR: + tool_dependency.status != self.install_model.ToolDependency.installation_status.ERROR: # If the tool dependency is not in an error state, perform any final actions that have been # defined within the actions_group tag set, but outside of an <actions> tag, which defines # the recipe for installing and compiling from source. @@ -419,17 +419,17 @@ actions_elem=actions_elems, action_elem=None ) if tool_dependency.status != self.install_model.ToolDependency.installation_status.ERROR: - log.debug( 'Tool dependency %s version %s has been installed in %s.' % \ - ( str( package_name ), str( package_version ), str( install_dir ) ) ) + log.debug( 'Tool dependency %s version %s has been installed in %s.' % + ( str( package_name ), str( package_version ), str( install_dir ) ) ) return tool_dependency def mark_tool_dependency_installed( self, tool_dependency ): if tool_dependency.status not in [ self.install_model.ToolDependency.installation_status.ERROR, self.install_model.ToolDependency.installation_status.INSTALLED ]: - log.debug( 'Changing status for tool dependency %s from %s to %s.' % \ - ( str( tool_dependency.name ), - str( tool_dependency.status ), - str( self.install_model.ToolDependency.installation_status.INSTALLED ) ) ) + log.debug( 'Changing status for tool dependency %s from %s to %s.' % + ( str( tool_dependency.name ), + str( tool_dependency.status ), + str( self.install_model.ToolDependency.installation_status.INSTALLED ) ) ) status = self.install_model.ToolDependency.installation_status.INSTALLED tool_dependency = tool_dependency_util.set_tool_dependency_attributes( self.app, tool_dependency=tool_dependency, @@ -531,10 +531,10 @@ self.install_model.context.add( tool_shed_repository ) self.install_model.context.flush() if 'tool_dependencies' in irmm_metadata_dict and not reinstalling: - tool_dependencies = tool_dependency_util.create_tool_dependency_objects( self.app, - tool_shed_repository, - relative_install_dir, - set_status=True ) + tool_dependency_util.create_tool_dependency_objects( self.app, + tool_shed_repository, + relative_install_dir, + set_status=True ) if 'sample_files' in irmm_metadata_dict: sample_files = irmm_metadata_dict.get( 'sample_files', [] ) tool_index_sample_files = tdtm.get_tool_index_sample_files( sample_files ) @@ -579,12 +579,12 @@ new_install=True ) if 'data_manager' in irmm_metadata_dict: dmh = data_manager.DataManagerHandler( self.app ) - new_data_managers = dmh.install_data_managers( self.app.config.shed_data_manager_config_file, - irmm_metadata_dict, - shed_config_dict, - relative_install_dir, - tool_shed_repository, - repository_tools_tups ) + dmh.install_data_managers( self.app.config.shed_data_manager_config_file, + irmm_metadata_dict, + shed_config_dict, + relative_install_dir, + tool_shed_repository, + repository_tools_tups ) if 'datatypes' in irmm_metadata_dict: tool_shed_repository.status = self.install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES if not tool_shed_repository.includes_datatypes: @@ -656,13 +656,9 @@ tool_shed_url = installation_dict[ 'tool_shed_url' ] # Handle contained tools. if includes_tools_for_display_in_tool_panel and ( new_tool_panel_section_label or tool_panel_section_id ): - tool_panel_section_key, tool_section = \ - self.tpm.handle_tool_panel_section( self.app.toolbox, - tool_panel_section_id=tool_panel_section_id, - new_tool_panel_section_label=new_tool_panel_section_label ) - else: - tool_panel_section_key = None - tool_section = None + self.tpm.handle_tool_panel_section( self.app.toolbox, + tool_panel_section_id=tool_panel_section_id, + new_tool_panel_section_label=new_tool_panel_section_label ) encoded_repository_ids = [ self.app.security.encode_id( tsr.id ) for tsr in created_or_updated_tool_shed_repositories ] new_kwd = dict( includes_tools=includes_tools, includes_tools_for_display_in_tool_panel=includes_tools_for_display_in_tool_panel, @@ -679,7 +675,7 @@ tool_shed_repository_ids=encoded_repository_ids, tool_shed_url=tool_shed_url ) encoded_kwd = encoding_util.tool_shed_encode( new_kwd ) - tsr_ids = [ r.id for r in created_or_updated_tool_shed_repositories ] + tsr_ids = [ r.id for r in created_or_updated_tool_shed_repositories ] tool_shed_repositories = [] for tsr_id in tsr_ids: tsr = self.install_model.context.query( self.install_model.ToolShedRepository ).get( tsr_id ) @@ -895,10 +891,10 @@ # Get the tool_dependencies.xml file from the repository. tool_dependencies_config = hg_util.get_config_from_disk( 'tool_dependencies.xml', install_dir ) itdm = InstallToolDependencyManager( self.app ) - installed_tool_dependencies = itdm.install_specified_tool_dependencies( tool_shed_repository=tool_shed_repository, - tool_dependencies_config=tool_dependencies_config, - tool_dependencies=tool_shed_repository.tool_dependencies, - from_tool_migration_manager=False ) + itdm.install_specified_tool_dependencies( tool_shed_repository=tool_shed_repository, + tool_dependencies_config=tool_dependencies_config, + tool_dependencies=tool_shed_repository.tool_dependencies, + from_tool_migration_manager=False ) basic_util.remove_dir( work_dir ) self.update_tool_shed_repository_status( tool_shed_repository, self.install_model.ToolShedRepository.installation_status.INSTALLED ) diff -r 97f46da40bb3767c6cf0d440b1d2d58e06edf5e6 -r 50062f6e9b47a36dad57393292611632908fe79a lib/tool_shed/galaxy_install/repair_repository_manager.py --- a/lib/tool_shed/galaxy_install/repair_repository_manager.py +++ b/lib/tool_shed/galaxy_install/repair_repository_manager.py @@ -65,7 +65,7 @@ repair_dict = {} irm = install_manager.InstallRepositoryManager( self.app ) # Get a dictionary of all repositories upon which the contents of the current repository_metadata - #record depend. + # record depend. repository_dependencies_dict = rdim.get_repository_dependencies_for_installed_tool_shed_repository( self.app, repository ) if repository_dependencies_dict: @@ -142,14 +142,14 @@ return repo_info_dict, tool_panel_section_key def repair_tool_shed_repository( self, repository, repo_info_dict ): - + def add_repair_dict_entry( repository_name, error_message ): if repository_name in repair_dict: repair_dict[ repository_name ].append( error_message ) else: repair_dict[ repository_name ] = [ error_message ] return repair_dict - + metadata = repository.metadata repair_dict = {} tpm = tool_panel_manager.ToolPanelManager( self.app ) diff -r 97f46da40bb3767c6cf0d440b1d2d58e06edf5e6 -r 50062f6e9b47a36dad57393292611632908fe79a lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py --- a/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py +++ b/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py @@ -38,13 +38,13 @@ for repo_info_dict in repo_info_dicts: for name, repo_info_tuple in repo_info_dict.items(): description, \ - repository_clone_url, \ - changeset_revision, \ - ctx_rev, \ - repository_owner, \ - repository_dependencies, \ - tool_dependencies = \ - suc.get_repo_info_tuple_contents( repo_info_tuple ) + repository_clone_url, \ + changeset_revision, \ + ctx_rev, \ + repository_owner, \ + repository_dependencies, \ + tool_dependencies = \ + suc.get_repo_info_tuple_contents( repo_info_tuple ) if repository_dependencies: for key, val in repository_dependencies.items(): if key in [ 'root_key', 'description' ]: @@ -71,12 +71,12 @@ for repository_dependency_components_list in val: required_repository = None rd_toolshed, \ - rd_name, \ - rd_owner, \ - rd_changeset_revision, \ - rd_prior_installation_required, \ - rd_only_if_compiling_contained_td = \ - common_util.parse_repository_dependency_tuple( repository_dependency_components_list ) + rd_name, \ + rd_owner, \ + rd_changeset_revision, \ + rd_prior_installation_required, \ + rd_only_if_compiling_contained_td = \ + common_util.parse_repository_dependency_tuple( repository_dependency_components_list ) # Get the the tool_shed_repository defined by rd_name, rd_owner and rd_changeset_revision. This # is the repository that will be required by the current d_repository. # TODO: Check tool_shed_repository.tool_shed as well when repository dependencies across tool sheds is supported. @@ -101,10 +101,10 @@ repository_dependency = self.get_repository_dependency_by_repository_id( install_model, required_repository.id ) if not repository_dependency: - log.debug( 'Creating new repository_dependency record for installed revision %s of repository: %s owned by %s.' % \ - ( str( required_repository.installed_changeset_revision ), - str( required_repository.name ), - str( required_repository.owner ) ) ) + log.debug( 'Creating new repository_dependency record for installed revision %s of repository: %s owned by %s.' % + ( str( required_repository.installed_changeset_revision ), + str( required_repository.name ), + str( required_repository.owner ) ) ) repository_dependency = install_model.RepositoryDependency( tool_shed_repository_id=required_repository.id ) install_model.context.add( repository_dependency ) install_model.context.flush() @@ -159,13 +159,13 @@ for name, repo_info_tuple in repo_info_dict.items(): can_update_db_record = False description, \ - repository_clone_url, \ - changeset_revision, \ - ctx_rev, \ - repository_owner, \ - repository_dependencies, \ - tool_dependencies = \ - suc.get_repo_info_tuple_contents( repo_info_tuple ) + repository_clone_url, \ + changeset_revision, \ + ctx_rev, \ + repository_owner, \ + repository_dependencies, \ + tool_dependencies = \ + suc.get_repo_info_tuple_contents( repo_info_tuple ) # See if the repository has an existing record in the database. repository_db_record, installed_changeset_revision = \ suc.repository_was_previously_installed( self.app, tool_shed_url, name, repo_info_tuple, from_tip=False ) @@ -190,8 +190,6 @@ # record in the database. name = repository_db_record.name installed_changeset_revision = repository_db_record.installed_changeset_revision - metadata_dict = repository_db_record.metadata - dist_to_shed = repository_db_record.dist_to_shed can_update_db_record = True elif repository_db_record.status in [ install_model.ToolShedRepository.installation_status.DEACTIVATED ]: # The current tool shed repository is deactivated, so updating its database record @@ -209,8 +207,6 @@ else: # No record exists in the database for the repository currently being processed. installed_changeset_revision = changeset_revision - metadata_dict = {} - dist_to_shed = False can_update_db_record = True if can_update_db_record: # The database record for the tool shed repository currently being processed can be updated. @@ -348,13 +344,10 @@ # a dependency of the dependent repository's contained tool dependency, and only if that # tool dependency requires compilation. # For backward compatibility to the 12/20/12 Galaxy release. - prior_installation_required = 'False' only_if_compiling_contained_td = 'False' if len( components_list ) == 4: - prior_installation_required = 'False' only_if_compiling_contained_td = 'False' elif len( components_list ) == 5: - prior_installation_required = components_list[ 4 ] only_if_compiling_contained_td = 'False' if not asbool( only_if_compiling_contained_td ): if components_list not in required_repository_tups: https://bitbucket.org/galaxy/galaxy-central/commits/032eefd299cb/ Changeset: 032eefd299cb User: jmchilton Date: 2014-12-28 16:23:44+00:00 Summary: Tweak two ToolShed modules to clarify they don't use ToolSection... ... objects (directly anyway). I would like to refactor all the tool shed components to not deal directly with ToolSection objects but instead just pass around IDs. Affected #: 2 files diff -r 50062f6e9b47a36dad57393292611632908fe79a -r 032eefd299cbfd103ea85103e64147d436068fb5 lib/tool_shed/galaxy_install/repair_repository_manager.py --- a/lib/tool_shed/galaxy_install/repair_repository_manager.py +++ b/lib/tool_shed/galaxy_install/repair_repository_manager.py @@ -123,7 +123,7 @@ tool_panel_section_name = section_dict[ 'name' ] if tool_panel_section_id: tpm = tool_panel_manager.ToolPanelManager( self.app ) - tool_panel_section_key, tool_panel_section = \ + tool_panel_section_key, _ = \ tpm.get_or_create_tool_section( self.app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=tool_panel_section_name ) @@ -165,7 +165,7 @@ suc.get_tool_panel_config_tool_path_install_dir( self.app, repository ) # Reset the repository attributes to the New state for installation. if metadata: - tool_section, tool_panel_section_key = \ + _, tool_panel_section_key = \ tpm.handle_tool_panel_selection( self.app.toolbox, metadata, no_changes_checked=True, diff -r 50062f6e9b47a36dad57393292611632908fe79a -r 032eefd299cbfd103ea85103e64147d436068fb5 lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py --- a/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py +++ b/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py @@ -213,7 +213,7 @@ # Get the repository metadata to see where it was previously located in the tool panel. tpm = tool_panel_manager.ToolPanelManager( self.app ) if repository_db_record and repository_db_record.metadata: - tool_section, tool_panel_section_key = \ + _, tool_panel_section_key = \ tpm.handle_tool_panel_selection( toolbox=self.app.toolbox, metadata=repository_db_record.metadata, no_changes_checked=no_changes_checked, @@ -221,7 +221,7 @@ new_tool_panel_section_label=new_tool_panel_section_label ) else: # We're installing a new tool shed repository that does not yet have a database record. - tool_panel_section_key, tool_section = \ + tool_panel_section_key, _ = \ tpm.handle_tool_panel_section( self.app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) https://bitbucket.org/galaxy/galaxy-central/commits/6d4909f34123/ Changeset: 6d4909f34123 User: jmchilton Date: 2014-12-28 16:23:44+00:00 Summary: More centralization of code for registering tools in ToolBox. Affected #: 1 file diff -r 032eefd299cbfd103ea85103e64147d436068fb5 -r 6d4909f34123fe53f1497dd2ea27a611039ae5c0 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -679,7 +679,7 @@ # changed, so the tool should always be reloaded here. We used to # only load the tool if it was not found in self.tools_by_id, but # performing that check did not enable this scenario. - self.tools_by_id[ tool.id ] = tool + self.register_tool( tool ) if load_panel_dict: self.__add_tool_to_tool_panel( tool, panel_dict, section=isinstance( panel_dict, ToolSection ) ) https://bitbucket.org/galaxy/galaxy-central/commits/b499a560826b/ Changeset: b499a560826b User: jmchilton Date: 2014-12-28 16:23:44+00:00 Summary: Eliminate one reference to ToolBox.tool_panel in install_manager.py. Affected #: 2 files diff -r 6d4909f34123fe53f1497dd2ea27a611039ae5c0 -r b499a560826b2d3a3cfc16dc44b99dafa7c3802e lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -1021,6 +1021,24 @@ status = 'done' return message, status + def find_section_id( self, tool_panel_section_id ): + """ + Find the section ID referenced by the key or return '' indicating + no such section id. + """ + if not tool_panel_section_id: + tool_panel_section_id = '' + else: + if tool_panel_section_id not in self.tool_panel: + # Hack introduced without comment in a29d54619813d5da992b897557162a360b8d610c- + # not sure why it is needed. + fixed_tool_panel_section_id = 'section_%s' % tool_panel_section_id + if fixed_tool_panel_section_id in self.tool_panel: + tool_panel_section_id = fixed_tool_panel_section_id + else: + tool_panel_section_id = '' + return tool_panel_section_id + def load_workflow( self, workflow_id ): """ Return an instance of 'Workflow' identified by `id`, diff -r 6d4909f34123fe53f1497dd2ea27a611039ae5c0 -r b499a560826b2d3a3cfc16dc44b99dafa7c3802e lib/tool_shed/galaxy_install/install_manager.py --- a/lib/tool_shed/galaxy_install/install_manager.py +++ b/lib/tool_shed/galaxy_install/install_manager.py @@ -742,16 +742,7 @@ tool_path = shed_config_dict[ 'tool_path' ] if not shed_tool_conf: raise exceptions.RequestParameterMissingException( "Missing required parameter 'shed_tool_conf'." ) - tool_panel_section_id = install_options.get( 'tool_panel_section_id', '' ) - if tool_panel_section_id not in [ None, '' ]: - if tool_panel_section_id not in self.app.toolbox.tool_panel: - fixed_tool_panel_section_id = 'section_%s' % tool_panel_section_id - if fixed_tool_panel_section_id in self.app.toolbox.tool_panel: - tool_panel_section_id = fixed_tool_panel_section_id - else: - tool_panel_section_id = '' - else: - tool_panel_section_id = '' + tool_panel_section_id = self.app.toolbox.find_section_id( install_options.get( 'tool_panel_section_id', '' ) ) # Build the dictionary of information necessary for creating tool_shed_repository database records # for each repository being installed. installation_dict = dict( install_repository_dependencies=install_repository_dependencies, https://bitbucket.org/galaxy/galaxy-central/commits/54b778976b7b/ Changeset: 54b778976b7b User: jmchilton Date: 2014-12-28 16:23:44+00:00 Summary: Simplify shed-y logic in load_tool_tag_set. Drops cycolomatic complexity from 14 to 10 for that method. Affected #: 2 files diff -r b499a560826b2d3a3cfc16dc44b99dafa7c3802e -r 54b778976b7bb297160955170fda6ff1efd2d62a lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -559,6 +559,23 @@ def tools( self ): return self.tools_by_id.iteritems() + def __elem_to_tool_shed_repository( self, elem ): + # The tool is contained in an installed tool shed repository, so load + # the tool only if the repository has not been marked deleted. + tool_shed = elem.find( "tool_shed" ).text + repository_name = elem.find( "repository_name" ).text + repository_owner = elem.find( "repository_owner" ).text + installed_changeset_revision_elem = elem.find( "installed_changeset_revision" ) + if installed_changeset_revision_elem is None: + # Backward compatibility issue - the tag used to be named 'changeset_revision'. + installed_changeset_revision_elem = elem.find( "changeset_revision" ) + installed_changeset_revision = installed_changeset_revision_elem.text + tool_shed_repository = self.__get_tool_shed_repository( tool_shed, + repository_name, + repository_owner, + installed_changeset_revision ) + return tool_shed_repository + def __get_tool_shed_repository( self, tool_shed, name, owner, installed_changeset_revision ): # We store only the port, if one exists, in the database. tool_shed = common_util.remove_protocol_from_tool_shed_url( tool_shed ) @@ -613,42 +630,29 @@ try: path = elem.get( "file" ) repository_id = None - if guid is None: - tool_shed_repository = None - can_load_into_panel_dict = True - else: + + tool_shed_repository = None + can_load_into_panel_dict = True + if guid is not None: # The tool is contained in an installed tool shed repository, so load # the tool only if the repository has not been marked deleted. - tool_shed = elem.find( "tool_shed" ).text - repository_name = elem.find( "repository_name" ).text - repository_owner = elem.find( "repository_owner" ).text - installed_changeset_revision_elem = elem.find( "installed_changeset_revision" ) - if installed_changeset_revision_elem is None: - # Backward compatibility issue - the tag used to be named 'changeset_revision'. - installed_changeset_revision_elem = elem.find( "changeset_revision" ) - installed_changeset_revision = installed_changeset_revision_elem.text - tool_shed_repository = self.__get_tool_shed_repository( tool_shed, - repository_name, - repository_owner, - installed_changeset_revision ) + tool_shed_repository = self.__elem_to_tool_shed_repository( elem ) if tool_shed_repository: # Only load tools if the repository is not deactivated or uninstalled. can_load_into_panel_dict = not tool_shed_repository.deleted repository_id = self.app.security.encode_id( tool_shed_repository.id ) - else: - # If there is not yet a tool_shed_repository record, we're in the process of installing - # a new repository, so any included tools can be loaded into the tool panel. - can_load_into_panel_dict = True + # Else there is not yet a tool_shed_repository record, we're in the process of installing + # a new repository, so any included tools can be loaded into the tool panel. tool = self.load_tool( os.path.join( tool_path, path ), guid=guid, repository_id=repository_id ) if string_as_bool(elem.get( 'hidden', False )): tool.hidden = True key = 'tool_%s' % str( tool.id ) if can_load_into_panel_dict: if guid is not None: - tool.tool_shed = tool_shed - tool.repository_name = repository_name - tool.repository_owner = repository_owner - tool.installed_changeset_revision = installed_changeset_revision + tool.tool_shed = tool_shed_repository.tool_shed + tool.repository_name = tool_shed_repository.name + tool.repository_owner = tool_shed_repository.owner + tool.installed_changeset_revision = tool_shed_repository.installed_changeset_revision tool.guid = guid tool.version = elem.find( "version" ).text # Make sure the tool has a tool_version. diff -r b499a560826b2d3a3cfc16dc44b99dafa7c3802e -r 54b778976b7bb297160955170fda6ff1efd2d62a test/unit/tools/test_toolbox.py --- a/test/unit/tools/test_toolbox.py +++ b/test/unit/tools/test_toolbox.py @@ -136,6 +136,27 @@ assert toolbox.get_tool( "test_tool" ) is not None assert toolbox.get_tool( "not_a_test_tool" ) is None + def test_tool_shed_properties( self ): + self._init_tool() + self._setup_two_versions_in_config( section=False ) + self._setup_two_versions() + + test_tool = self.toolbox.get_tool( "test_tool" ) + assert test_tool.tool_shed == "github.com" + assert test_tool.repository_owner == "galaxyproject" + assert test_tool.repository_name == "example" + assert test_tool.installed_changeset_revision == "1" + + def test_tool_shed_properties_only_on_installed_tools( self ): + self._init_tool() + self._add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) + toolbox = self.toolbox + test_tool = toolbox.get_tool( "test_tool" ) + assert test_tool.tool_shed is None + assert test_tool.repository_name is None + assert test_tool.repository_owner is None + assert test_tool.installed_changeset_revision is None + def test_load_file_in_section( self ): self._init_tool() self._add_config( """<toolbox><section id="t" name="test"><tool file="tool.xml" /></section></toolbox>""" ) https://bitbucket.org/galaxy/galaxy-central/commits/1912dec92b72/ Changeset: 1912dec92b72 User: jmchilton Date: 2014-12-28 16:23:44+00:00 Summary: De-duplication for loading elements into the tool panel. Create one public method load_item on ToolBox that should be used externally instead of load_tool_tag_set, load_section_tag_set, etc.... This reduces the duplication within the toolbox and between the toolbox and the Tool Shed's ToolPanelManager. Probably more importantly it also is another step down the road toward hiding implementation details such as toolbox.tool_panel and toolbox.intergrated_tool_panel from the ToolPanelManager. Already had unit test coverage for ToolPanelManager stuff here - but added test coverage for loading labels, workflows, and tool directories. Affected #: 3 files diff -r 54b778976b7bb297160955170fda6ff1efd2d62a -r 1912dec92b728b974094456be8eb6d84d34a7ca6 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -222,16 +222,14 @@ self.index += 1 if parsing_shed_tool_conf: config_elems.append( elem ) - if elem.tag == 'tool': - self.load_tool_tag_set( elem, self.tool_panel, self.integrated_tool_panel, tool_path, load_panel_dict, guid=elem.get( 'guid' ), index=index ) - elif elem.tag == 'workflow': - self.load_workflow_tag_set( elem, self.tool_panel, self.integrated_tool_panel, load_panel_dict, index=index ) - elif elem.tag == 'section': - self.load_section_tag_set( elem, tool_path, load_panel_dict, index=index ) - elif elem.tag == 'label': - self.load_label_tag_set( elem, self.tool_panel, self.integrated_tool_panel, load_panel_dict, index=index ) - elif elem.tag == 'tool_dir': - self.load_tooldir_tag_set( elem, self.tool_panel, self.integrated_tool_panel, tool_path, load_panel_dict ) + self.load_item( + elem, + tool_path=tool_path, + load_panel_dict=load_panel_dict, + guid=elem.get( 'guid' ), + index=index, + internal=True + ) if parsing_shed_tool_conf: shed_tool_conf_dict = dict( config_filename=config_filename, @@ -239,6 +237,28 @@ config_elems=config_elems ) self.shed_tool_confs.append( shed_tool_conf_dict ) + def load_item( self, elem, tool_path, panel_dict=None, integrated_panel_dict=None, load_panel_dict=True, guid=None, index=None, internal=False ): + item_type = elem.tag + if item_type not in ['tool', 'section'] and not internal: + # External calls from tool shed code cannot load labels or tool + # directories. + return + + if panel_dict is None: + panel_dict = self.tool_panel + if integrated_panel_dict is None: + integrated_panel_dict = self.integrated_tool_panel + if item_type == 'tool': + self.load_tool_tag_set( elem, panel_dict=panel_dict, integrated_panel_dict=integrated_panel_dict, tool_path=tool_path, load_panel_dict=load_panel_dict, guid=guid, index=index ) + elif item_type == 'workflow': + self.load_workflow_tag_set( elem, panel_dict=panel_dict, integrated_panel_dict=integrated_panel_dict, load_panel_dict=load_panel_dict, index=index ) + elif item_type == 'section': + self.load_section_tag_set( elem, tool_path=tool_path, load_panel_dict=load_panel_dict, index=index ) + elif item_type == 'label': + self.load_label_tag_set( elem, panel_dict=panel_dict, integrated_panel_dict=integrated_panel_dict, load_panel_dict=load_panel_dict, index=index ) + elif item_type == 'tool_dir': + self.load_tooldir_tag_set( elem, panel_dict, tool_path, integrated_panel_dict, load_panel_dict=load_panel_dict ) + def get_shed_config_dict_by_filename( self, filename, default=None ): for shed_config_dict in self.shed_tool_confs: if shed_config_dict[ 'config_filename' ] == filename: @@ -729,14 +749,16 @@ integrated_section = ToolSection( elem ) integrated_elems = integrated_section.elems for sub_index, sub_elem in enumerate( elem ): - if sub_elem.tag == 'tool': - self.load_tool_tag_set( sub_elem, elems, integrated_elems, tool_path, load_panel_dict, guid=sub_elem.get( 'guid' ), index=sub_index ) - elif sub_elem.tag == 'workflow': - self.load_workflow_tag_set( sub_elem, elems, integrated_elems, load_panel_dict, index=sub_index ) - elif sub_elem.tag == 'label': - self.load_label_tag_set( sub_elem, elems, integrated_elems, load_panel_dict, index=sub_index ) - elif sub_elem.tag == 'tool_dir': - self.load_tooldir_tag_set( sub_elem, elems, tool_path, integrated_elems, load_panel_dict ) + self.load_item( + sub_elem, + tool_path=tool_path, + panel_dict=elems, + integrated_panel_dict=integrated_elems, + load_panel_dict=load_panel_dict, + guid=sub_elem.get( 'guid' ), + index=sub_index, + internal=True, + ) if load_panel_dict: self.tool_panel[ key ] = section # Always load sections into the integrated_tool_panel. diff -r 54b778976b7bb297160955170fda6ff1efd2d62a -r 1912dec92b728b974094456be8eb6d84d34a7ca6 lib/tool_shed/galaxy_install/tools/tool_panel_manager.py --- a/lib/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -58,22 +58,12 @@ # Add the new elements to the in-memory list of config_elems. config_elems.append( config_elem ) # Load the tools into the in-memory tool panel. - if config_elem.tag == 'section': - self.app.toolbox.load_section_tag_set( config_elem, tool_path, load_panel_dict=True ) - elif config_elem.tag == 'workflow': - self.app.toolbox.load_workflow_tag_set( config_elem, - self.app.toolbox.tool_panel, - self.app.toolbox.integrated_tool_panel, - load_panel_dict=True ) - elif config_elem.tag == 'tool': - self.app.toolbox.load_tool_tag_set( - config_elem, - self.app.toolbox.tool_panel, - self.app.toolbox.integrated_tool_panel, - tool_path, - load_panel_dict=True, - guid=config_elem.get( 'guid' ) - ) + self.app.toolbox.load_item( + config_elem, + tool_path=tool_path, + load_panel_dict=True, + guid=config_elem.get( 'guid' ), + ) # Replace the old list of in-memory config_elems with the new list for this shed_tool_conf_dict. shed_tool_conf_dict[ 'config_elems' ] = config_elems self.app.toolbox.update_shed_config( index, shed_tool_conf_dict ) diff -r 54b778976b7bb297160955170fda6ff1efd2d62a -r 1912dec92b728b974094456be8eb6d84d34a7ca6 test/unit/tools/test_toolbox.py --- a/test/unit/tools/test_toolbox.py +++ b/test/unit/tools/test_toolbox.py @@ -3,6 +3,7 @@ import unittest from galaxy.tools import ToolBox +from galaxy import model from galaxy.model import tool_shed_install from galaxy.model.tool_shed_install import mapping import tools_support @@ -216,6 +217,67 @@ 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 test_tool_dir( self ): + self._init_tool() + self._add_config( """<toolbox><tool_dir dir="%s" /></toolbox>""" % self.test_directory ) + + toolbox = self.toolbox + assert toolbox.get_tool( "test_tool" ) is not None + + def test_workflow_in_panel( self ): + stored_workflow = self.__test_workflow() + encoded_id = self.app.security.encode_id( stored_workflow.id ) + self._add_config( """<toolbox><workflow id="%s" /></toolbox>""" % encoded_id ) + assert len( self.toolbox.tool_panel ) == 1 + panel_workflow = self.toolbox.tool_panel.values()[ 0 ] + assert panel_workflow == stored_workflow.latest_workflow + # TODO: test to_dict with workflows + + def test_workflow_in_section( self ): + stored_workflow = self.__test_workflow() + encoded_id = self.app.security.encode_id( stored_workflow.id ) + self._add_config( """<toolbox><section id="tid" name="TID"><workflow id="%s" /></section></toolbox>""" % encoded_id ) + assert len( self.toolbox.tool_panel ) == 1 + section = self.toolbox.tool_panel[ 'tid' ] + assert len( section.elems ) == 1 + panel_workflow = section.elems.values()[ 0 ] + assert panel_workflow == stored_workflow.latest_workflow + + def test_label_in_panel( self ): + self._add_config( """<toolbox><label id="lab1" text="Label 1" /><label id="lab2" text="Label 2" /></toolbox>""" ) + assert len( self.toolbox.tool_panel ) == 2 + self.__check_test_labels( self.toolbox.tool_panel ) + + def test_label_in_section( self ): + self._add_config( """<toolbox><section id="tid" name="TID"><label id="lab1" text="Label 1" /><label id="lab2" text="Label 2" /></section></toolbox>""" ) + assert len( self.toolbox.tool_panel ) == 1 + section = self.toolbox.tool_panel[ 'tid' ] + self.__check_test_labels( section.elems ) + + def __check_test_labels( self, panel_dict ): + assert panel_dict.keys() == ["label_lab1", "label_lab2"] + label1 = panel_dict.values()[ 0 ] + assert label1.id == "lab1" + assert label1.text == "Label 1" + + label2 = panel_dict[ "label_lab2" ] + assert label2.id == "lab2" + assert label2.text == "Label 2" + + def __test_workflow( self ): + stored_workflow = model.StoredWorkflow() + workflow = model.Workflow() + workflow.stored_workflow = stored_workflow + stored_workflow.latest_workflow = workflow + user = model.User() + user.email = "test@example.com" + user.password = "passw0rD1" + stored_workflow.user = user + self.app.model.context.add( workflow ) + self.app.model.context.add( stored_workflow ) + self.app.model.context.flush() + return stored_workflow + 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 ) 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.