Skip to content

Commit

Permalink
Merge pull request #14612 from jmchilton/ts_unused_1
Browse files Browse the repository at this point in the history
Remove unused tool shed functions.
  • Loading branch information
mvdbeek authored Sep 14, 2022
2 parents f3912e9 + 3fe2674 commit 2ee253c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 162 deletions.
157 changes: 1 addition & 156 deletions lib/galaxy/util/tool_shed/common_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import errno
import json
import logging
import os
Expand All @@ -7,10 +6,7 @@
from routes import url_for

from galaxy import util
from galaxy.util.tool_shed import (
encoding_util,
xml_util,
)
from galaxy.util.tool_shed import encoding_util

log = logging.getLogger(__name__)

Expand All @@ -26,101 +22,6 @@ def accumulate_tool_dependencies(tool_shed_accessible, tool_dependencies, all_to
return all_tool_dependencies


def check_for_missing_tools(app, tool_panel_configs, latest_tool_migration_script_number):
# Get the 000x_tools.xml file associated with the current migrate_tools version number.
tools_xml_file_path = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.pardir,
"galaxy_install",
"migrate",
"scripts",
"%04d_tools.xml" % latest_tool_migration_script_number,
)
)
# Parse the XML and load the file attributes for later checking against the proprietary tool_panel_config.
migrated_tool_configs_dict = {}
tree, error_message = xml_util.parse_xml(tools_xml_file_path)
if tree is None:
return False, {}
root = tree.getroot()
tool_shed = root.get("name")
tool_shed_url = get_tool_shed_url_from_tool_shed_registry(app, tool_shed)
# The default behavior is that the tool shed is down.
tool_shed_accessible = False
missing_tool_configs_dict = {}
if tool_shed_url:
for elem in root:
if elem.tag == "repository":
repository_dependencies = []
all_tool_dependencies = []
repository_name = elem.get("name")
changeset_revision = elem.get("changeset_revision")
tool_shed_accessible, repository_dependencies_dict = get_repository_dependencies(
app, tool_shed_url, repository_name, REPOSITORY_OWNER, changeset_revision
)
if tool_shed_accessible:
# Accumulate all tool dependencies defined for repository dependencies for display to the user.
for rd_key, rd_tups in repository_dependencies_dict.items():
if rd_key in ["root_key", "description"]:
continue
for rd_tup in rd_tups:
(
tool_shed,
name,
owner,
changeset_revision,
prior_installation_required,
only_if_compiling_contained_td,
) = parse_repository_dependency_tuple(rd_tup)
tool_shed_accessible, tool_dependencies = get_tool_dependencies(
app, tool_shed_url, name, owner, changeset_revision
)
all_tool_dependencies = accumulate_tool_dependencies(
tool_shed_accessible, tool_dependencies, all_tool_dependencies
)
tool_shed_accessible, tool_dependencies = get_tool_dependencies(
app, tool_shed_url, repository_name, REPOSITORY_OWNER, changeset_revision
)
all_tool_dependencies = accumulate_tool_dependencies(
tool_shed_accessible, tool_dependencies, all_tool_dependencies
)
for tool_elem in elem.findall("tool"):
tool_config_file_name = tool_elem.get("file")
if tool_config_file_name:
# We currently do nothing with repository dependencies except install them (we do not display repositories that will be
# installed to the user). However, we'll store them in the following dictionary in case we choose to display them in the
# future.
dependencies_dict = dict(
tool_dependencies=all_tool_dependencies, repository_dependencies=repository_dependencies
)
migrated_tool_configs_dict[tool_config_file_name] = dependencies_dict
else:
break
if tool_shed_accessible:
# Parse the proprietary tool_panel_configs (the default is tool_conf.xml) and generate the list of missing tool config file names.
for tool_panel_config in tool_panel_configs:
tree, error_message = xml_util.parse_xml(tool_panel_config)
if tree:
root = tree.getroot()
for elem in root:
if elem.tag == "tool":
missing_tool_configs_dict = check_tool_tag_set(
elem, migrated_tool_configs_dict, missing_tool_configs_dict
)
elif elem.tag == "section":
for section_elem in elem:
if section_elem.tag == "tool":
missing_tool_configs_dict = check_tool_tag_set(
section_elem, migrated_tool_configs_dict, missing_tool_configs_dict
)
else:
exception_msg = f"\n\nThe entry for the main Galaxy tool shed at {tool_shed} is missing from the {app.config.tool_sheds_config} file. "
exception_msg += "The entry for this tool shed must always be available in this file, so re-add it before attempting to start your Galaxy server.\n"
raise Exception(exception_msg)
return tool_shed_accessible, missing_tool_configs_dict


def check_tool_tag_set(elem, migrated_tool_configs_dict, missing_tool_configs_dict):
file_path = elem.get("file", None)
if file_path:
Expand Down Expand Up @@ -164,31 +65,6 @@ def generate_clone_url_from_repo_info_tup(app, repo_info_tup):
return util.build_url(tool_shed_url, pathspec=["repos", owner, name])


def get_non_shed_tool_panel_configs(app):
"""Get the non-shed related tool panel configs - there can be more than one, and the default is tool_conf.xml."""
config_filenames = []
for config_filename in app.config.tool_configs:
# Any config file that includes a tool_path attribute in the root tag set like the following is shed-related.
# <toolbox tool_path="database/shed_tools">
try:
tree, error_message = xml_util.parse_xml(config_filename)
except OSError as exc:
if (
config_filename == app.config.shed_tool_conf
and not app.config.shed_tool_conf_set
and exc.errno == errno.ENOENT
):
continue
raise
if tree is None:
continue
root = tree.getroot()
tool_path = root.get("tool_path", None)
if tool_path is None:
config_filenames.append(config_filename)
return config_filenames


def get_repository_dependencies(app, tool_shed_url, repository_name, repository_owner, changeset_revision):
repository_dependencies_dict = {}
tool_shed_accessible = True
Expand Down Expand Up @@ -227,34 +103,6 @@ def get_protocol_from_tool_shed_url(tool_shed_url):
return "http"


def get_tool_dependencies(app, tool_shed_url, repository_name, repository_owner, changeset_revision):
tool_dependencies = []
tool_shed_accessible = True
params = dict(name=repository_name, owner=repository_owner, changeset_revision=changeset_revision)
pathspec = ["repository", "get_tool_dependencies"]
try:
text = util.url_get(
tool_shed_url, auth=app.tool_shed_registry.url_auth(tool_shed_url), pathspec=pathspec, params=params
)
tool_shed_accessible = True
except Exception as e:
tool_shed_accessible = False
log.warning(
"The URL\n%s\nraised the exception:\n%s\n",
util.build_url(tool_shed_url, pathspec=pathspec, params=params),
e,
)
if tool_shed_accessible:
if text:
tool_dependencies_dict = encoding_util.tool_shed_decode(text)
for requirements_dict in tool_dependencies_dict.values():
tool_dependency_name = requirements_dict["name"]
tool_dependency_version = requirements_dict["version"]
tool_dependency_type = requirements_dict["type"]
tool_dependencies.append((tool_dependency_name, tool_dependency_version, tool_dependency_type))
return tool_shed_accessible, tool_dependencies


def get_tool_shed_repository_ids(as_string=False, **kwd):
tsrid = kwd.get("tool_shed_repository_id", None)
tsridslist = util.listify(kwd.get("tool_shed_repository_ids", None))
Expand Down Expand Up @@ -432,15 +280,12 @@ def remove_protocol_from_tool_shed_url(tool_shed_url):

__all__ = (
"accumulate_tool_dependencies",
"check_for_missing_tools",
"check_tool_tag_set",
"generate_clone_url_for_installed_repository",
"generate_clone_url_for_repository_in_tool_shed",
"generate_clone_url_from_repo_info_tup",
"get_non_shed_tool_panel_configs",
"get_repository_dependencies",
"get_protocol_from_tool_shed_url",
"get_tool_dependencies",
"get_tool_shed_repository_ids",
"get_tool_shed_url_from_tool_shed_registry",
"get_tool_shed_repository_url",
Expand Down
6 changes: 0 additions & 6 deletions lib/tool_shed/util/common_util.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from galaxy.util.tool_shed.common_util import (
accumulate_tool_dependencies,
check_for_missing_tools,
check_tool_tag_set,
generate_clone_url_for_installed_repository,
generate_clone_url_for_repository_in_tool_shed,
generate_clone_url_from_repo_info_tup,
get_non_shed_tool_panel_configs,
get_protocol_from_tool_shed_url,
get_repository_dependencies,
get_tool_dependencies,
get_tool_shed_repository_ids,
get_tool_shed_repository_url,
get_tool_shed_url_from_tool_shed_registry,
Expand All @@ -24,15 +21,12 @@

__all__ = (
"accumulate_tool_dependencies",
"check_for_missing_tools",
"check_tool_tag_set",
"generate_clone_url_for_installed_repository",
"generate_clone_url_for_repository_in_tool_shed",
"generate_clone_url_from_repo_info_tup",
"get_non_shed_tool_panel_configs",
"get_repository_dependencies",
"get_protocol_from_tool_shed_url",
"get_tool_dependencies",
"get_tool_shed_repository_ids",
"get_tool_shed_url_from_tool_shed_registry",
"get_tool_shed_repository_url",
Expand Down

0 comments on commit 2ee253c

Please sign in to comment.