This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

galaxy.tool_shed.util package


galaxy.tool_shed.util.basic_util module

galaxy.tool_shed.util.basic_util.get_file_type_str(changeset_revision, file_type)[source]
galaxy.tool_shed.util.basic_util.move_file(current_dir, source, destination, rename_to=None)[source]

Attempt to remove a directory from disk.

galaxy.tool_shed.util.basic_util.size_string(raw_text, size=32768)[source]

Return a subset of a string (up to MAX_DISPLAY_SIZE) translated to a safe string for display in a browser.


Attempt to strip the path from a file name.


Translates the characters in text to an html string

galaxy.tool_shed.util.container_util module

galaxy.tool_shed.util.container_util.generate_repository_dependencies_key_for_repository(toolshed_base_url: str, repository_name: str, repository_owner: str, changeset_revision: str, prior_installation_required: bool | str, only_if_compiling_contained_td: bool | str) str[source]

Assumes tool shed is current tool shed since repository dependencies across tool sheds is not yet supported.

galaxy.tool_shed.util.container_util.get_components_from_key(key: str) tuple[source]

Assumes tool shed is current tool shed since repository dependencies across tool sheds is not yet supported.

galaxy.tool_shed.util.hg_util module

galaxy.tool_shed.util.hg_util.clone_repository(repository_clone_url: str, repository_file_dir: str, ctx_rev=None) Tuple[bool, str | None][source]

Clone the repository up to the specified changeset_revision. No subsequent revisions will be present in the cloned repository.

galaxy.tool_shed.util.hg_util.copy_file_from_manifest(repo, changeset_revision, filename, dir)[source]

Copy the latest version of the file named filename from the repository manifest to the directory to which dir refers.

galaxy.tool_shed.util.hg_util.get_changectx_for_changeset(repo, changeset_revision, **kwd)[source]

Retrieve a specified changectx from a repository.

galaxy.tool_shed.util.hg_util.get_config_from_disk(config_file: str, relative_install_dir: str) str | None[source]
galaxy.tool_shed.util.hg_util.get_ctx_file_path_from_manifest(filename, repo, changeset_revision)[source]

Get the ctx file path for the latest revision of filename from the repository manifest up to the value of changeset_revision.

galaxy.tool_shed.util.hg_util.get_file_context_from_ctx(ctx, filename)[source]

Return the mercurial file context for a specified file.

galaxy.tool_shed.util.hg_util.pull_repository(repo_path, repository_clone_url, ctx_rev)[source]

Pull changes from a remote repository to a local one.

galaxy.tool_shed.util.hg_util.reversed_lower_upper_bounded_changelog(repo, excluded_lower_bounds_changeset_revision, included_upper_bounds_changeset_revision)[source]

Return a reversed list of changesets in the repository changelog after the excluded_lower_bounds_changeset_revision, but up to and including the included_upper_bounds_changeset_revision. The value of excluded_lower_bounds_changeset_revision will be the value of INITIAL_CHANGELOG_HASH if no valid changesets exist before included_upper_bounds_changeset_revision.

galaxy.tool_shed.util.hg_util.reversed_upper_bounded_changelog(repo, included_upper_bounds_changeset_revision)[source]

Return a reversed list of changesets in the repository changelog up to and including the included_upper_bounds_changeset_revision.

galaxy.tool_shed.util.hg_util.update_repository(repo_path, ctx_rev=None)[source]

Update the cloned repository to changeset_revision. It is critical that the installed repository is updated to the desired changeset_revision before metadata is set because the process for setting metadata uses the repository files on disk.

galaxy.tool_shed.util.metadata_util module

galaxy.tool_shed.util.metadata_util.get_updated_changeset_revisions_from_tool_shed(app, tool_shed_url, name, owner, changeset_revision)[source]

Get all appropriate newer changeset revisions for the repository defined by the received tool_shed_url / name / owner combination.

galaxy.tool_shed.util.repository_util module

galaxy.tool_shed.util.repository_util.check_for_updates(tool_shed_registry: Registry, install_model_context: install_model_scoped_session, repository_id: int | None = None) Tuple[str, str][source]
galaxy.tool_shed.util.repository_util.create_or_update_tool_shed_repository(app, name, description, installed_changeset_revision, ctx_rev, repository_clone_url, status, metadata_dict=None, current_changeset_revision=None, owner='', dist_to_shed=False)[source]

Update a tool shed repository record in the Galaxy database with the new information received. If a record defined by the received tool shed, repository name and owner does not exist, create a new record with the received information.


Extract the repository components from the provided tuple in a backward-compatible manner.

galaxy.tool_shed.util.repository_util.generate_tool_shed_repository_install_dir(repository_clone_url, changeset_revision)[source]

Generate a repository installation directory that guarantees repositories with the same name will always be installed in different directories. The tool path will be of the form: <tool shed url>/repos/<repository owner>/<repository name>/<installed changeset revision>

galaxy.tool_shed.util.repository_util.get_absolute_path_to_file_in_repository(repo_files_dir, file_name)[source]

Return the absolute path to a specified disk file contained in a repository.

galaxy.tool_shed.util.repository_util.get_ids_of_tool_shed_repositories_being_installed(app, as_string=False)[source]
galaxy.tool_shed.util.repository_util.get_installed_repository(app, tool_shed=None, name=None, owner=None, changeset_revision=None, installed_changeset_revision=None, repository_id=None, from_cache=False)[source]

Return a tool shed repository database record defined by the combination of a toolshed, repository name, repository owner and either current or originally installed changeset_revision.

galaxy.tool_shed.util.repository_util.get_installed_tool_shed_repository(app, id)[source]

Get a tool shed repository record from the Galaxy database defined by the id.

galaxy.tool_shed.util.repository_util.get_prior_import_or_install_required_dict(app, tsr_ids, repo_info_dicts)[source]

This method is used in the Tool Shed when exporting a repository and its dependencies, and in Galaxy when a repository and its dependencies are being installed. Return a dictionary whose keys are the received tsr_ids and whose values are a list of tsr_ids, each of which is contained in the received list of tsr_ids and whose associated repository must be imported or installed prior to the repository associated with the tsr_id key.

galaxy.tool_shed.util.repository_util.get_repo_info_tuple_contents(repo_info_tuple: Tuple[str, str, str, str, str, Dict[str, Dict[str, Any] | List[Dict[str, Any]]]] | Tuple[str, str, str, str, str, Any | None, Dict[str, Dict[str, Any] | List[Dict[str, Any]]]]) Tuple[str, str, str, str, str, Any | None, Dict[str, Dict[str, Any] | List[Dict[str, Any]]]][source]

Take care in handling the repo_info_tuple as it evolves over time as new tool shed features are introduced.

galaxy.tool_shed.util.repository_util.get_repository_admin_role_name(repository_name, repository_owner)[source]
galaxy.tool_shed.util.repository_util.get_repository_and_repository_dependencies_from_repo_info_dict(app, repo_info_dict)[source]

Return a tool_shed_repository or repository record defined by the information in the received repo_info_dict.

galaxy.tool_shed.util.repository_util.get_repository_by_id(app, id)[source]

Get a repository from the database via id.

galaxy.tool_shed.util.repository_util.get_repository_by_name(app, name)[source]

Get a repository from the database via name.

galaxy.tool_shed.util.repository_util.get_repository_by_name_and_owner(app, name, owner, eagerload_columns=None)[source]

Get a repository from the database via name and owner


Inspect the received list of repository_dependencies tuples and return boolean values for has_repository_dependencies and has_repository_dependencies_only_if_compiling_contained_td.

galaxy.tool_shed.util.repository_util.get_repository_for_dependency_relationship(app, tool_shed, name, owner, changeset_revision)[source]

Return an installed tool_shed_repository database record that is defined by either the current changeset revision or the installed_changeset_revision.

galaxy.tool_shed.util.repository_util.get_repository_ids_requiring_prior_import_or_install(app, tsr_ids, repository_dependencies)[source]

This method is used in the Tool Shed when exporting a repository and its dependencies, and in Galaxy when a repository and its dependencies are being installed. Inspect the received repository_dependencies and determine if the encoded id of each required repository is in the received tsr_ids. If so, then determine whether that required repository should be imported / installed prior to its dependent repository. Return a list of encoded repository ids, each of which is contained in the received list of tsr_ids, and whose associated repositories must be imported / installed prior to the dependent repository associated with the received repository_dependencies.


Gvien a “cleaned” repository clone URL, return the owner of the repository.


Given a repository clone URL, return the owner of the repository.

galaxy.tool_shed.util.repository_util.get_role_by_id(app, role_id)[source]

Get a Role from the database by id.

galaxy.tool_shed.util.repository_util.get_tool_shed_repository_by_id(app, repository_id) ToolShedRepository[source]

Return a tool shed repository database record defined by the id.

galaxy.tool_shed.util.repository_util.get_tool_shed_status_for_installed_repository(app, repository: ToolShedRepository)[source]

Send a request to the tool shed to retrieve information about newer installable repository revisions, current revision updates, whether the repository revision is the latest downloadable revision, and whether the repository has been deprecated in the tool shed. The received repository is a ToolShedRepository object from Galaxy.


The tool shed and clients to the tool (i.e. Galaxy) require a lot of similar functionality in this file but with small differences. This method should determine if the app performing the action is the tool shed or a client of the tool shed.

galaxy.tool_shed.util.repository_util.repository_was_previously_installed(app, tool_shed_url, repository_name, repo_info_tuple, from_tip=False)[source]

Find out if a repository is already installed into Galaxy - there are several scenarios where this is necessary. For example, this method will handle the case where the repository was previously installed using an older changeset_revsion, but later the repository was updated in the tool shed and now we’re trying to install the latest changeset revision of the same repository instead of updating the one that was previously installed. We’ll look in the database instead of on disk since the repository may be currently uninstalled.

galaxy.tool_shed.util.repository_util.set_repository_attributes(app, repository, status, error_message, deleted, uninstalled, remove_from_disk=False)[source]

galaxy.tool_shed.util.shed_util_common module

galaxy.tool_shed.util.shed_util_common.can_eliminate_repository_dependency(metadata_dict, tool_shed_url, name, owner)[source]

Determine if the relationship between a repository_dependency record associated with a tool_shed_repository record on the Galaxy side can be eliminated.

galaxy.tool_shed.util.shed_util_common.clean_dependency_relationships(trans, metadata_dict, tool_shed_repository, tool_shed_url)[source]

Repositories of type tool_dependency_definition allow for defining a package dependency at some point in the change log and then removing the dependency later in the change log. This function keeps the dependency relationships on the Galaxy side current by deleting database records that defined the now-broken relationships.

galaxy.tool_shed.util.shed_util_common.generate_tool_guid(repository_clone_url, tool)[source]

Generate a guid for the installed tool. It is critical that this guid matches the guid for the tool in the Galaxy tool shed from which it is being installed. The form of the guid is <tool shed host>/repos/<repository owner>/<repository name>/<tool id>/<tool version>

galaxy.tool_shed.util.shed_util_common.get_ctx_rev(app, tool_shed_url, name, owner, changeset_revision)[source]

Send a request to the tool shed to retrieve the ctx_rev for a repository defined by the combination of a name, owner and changeset revision.

galaxy.tool_shed.util.shed_util_common.get_next_prior_import_or_install_required_dict_entry(prior_required_dict, processed_tsr_ids)[source]

This method is used in the Tool Shed when exporting a repository and its dependencies, and in Galaxy when a repository and its dependencies are being installed. The order in which the prior_required_dict is processed is critical in order to ensure that the ultimate repository import or installation order is correctly defined. This method determines the next key / value pair from the received prior_required_dict that should be processed.

galaxy.tool_shed.util.shed_util_common.get_tool_panel_config_tool_path_install_dir(app, repository)[source]

Return shed-related tool panel config, the tool_path configured in it, and the relative path to the directory where the repository is installed. This method assumes all repository tools are defined in a single shed-related tool panel config.

galaxy.tool_shed.util.shed_util_common.get_user(app, id)[source]

Get a user from the database by id.

galaxy.tool_shed.util.shed_util_common.set_image_paths(app, text, encoded_repository_id=None, tool_shed_repository=None, tool_id=None, tool_version=None)[source]

Handle tool help image display for tools that are contained in repositories in the tool shed or installed into Galaxy as well as image display in repository README files. This method will determine the location of the image file and return the path to it that will enable the caller to open the file.

galaxy.tool_shed.util.tool_dependency_util module

galaxy.tool_shed.util.tool_dependency_util.get_tool_dependency(app, id)[source]

Get a tool_dependency from the database via id

galaxy.tool_shed.util.tool_dependency_util.get_tool_dependency_by_name_type_repository(app, repository, name, type)[source]
galaxy.tool_shed.util.tool_dependency_util.get_tool_dependency_by_name_version_type(app, name, version, type)[source]
galaxy.tool_shed.util.tool_dependency_util.get_tool_dependency_by_name_version_type_repository(app, repository, name, version, type)[source]
galaxy.tool_shed.util.tool_dependency_util.get_tool_dependency_ids(as_string=False, **kwd)[source]
galaxy.tool_shed.util.tool_dependency_util.parse_package_elem(package_elem, platform_info_dict=None, include_after_install_actions=True)[source]

Parse a <package> element within a tool dependency definition and return a list of action tuples. This method is called when setting metadata on a repository that includes a tool_dependencies.xml file or when installing a repository that includes a tool_dependencies.xml file. If installing, platform_info_dict must be a valid dictionary and include_after_install_actions must be True.

galaxy.tool_shed.util.tool_dependency_util.remove_tool_dependency(app, tool_dependency)[source]

The received tool_dependency must be in an error state.


galaxy.tool_shed.util.tool_util module


Build a SelectField whose options are the keys in app.toolbox.shed_tool_confs.


Build a SelectField whose options are the sections of the current in-memory toolbox.

galaxy.tool_shed.util.tool_util.copy_sample_file(tool_data_path: str, filename: str, dest_path: str | None = None) str[source]

Copies a sample file at filename to the dest_path directory and strips the ‘.sample’ extensions from filename. Returns the path to the copied file (with the .sample extension).

galaxy.tool_shed.util.tool_util.copy_sample_files(tool_data_path: str, sample_files, tool_path: str | None = None, sample_files_copied=None, dest_path: str | None = None) None[source]

Copy all appropriate files to dest_path in the local Galaxy environment that have not already been copied. Those that have been copied are contained in sample_files_copied. The default value for dest_path is ~/tool-data. We need to be careful to copy only appropriate files here because tool shed repositories can contain files ending in .sample that should not be copied to the ~/tool-data directory.

galaxy.tool_shed.util.tool_util.generate_message_for_invalid_tools(app, invalid_file_tups: list, repository, metadata_dict: dict | None, as_html: bool = True, displaying_invalid_tool: bool = False) str[source]
galaxy.tool_shed.util.tool_util.handle_missing_index_file(app, tool_path, sample_files, repository_tools_tups, sample_files_copied)[source]

Inspect each tool to see if it has any input parameters that are dynamically generated select lists that depend on a .loc file. This method is not called from the tool shed, but from Galaxy when a repository is being installed.