mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
LazyToolBox: drop _lookup_tool_shed_repository; use ToolConfRepository stub
``_create_tool_from_stored_source`` was hitting the install database on every shed-tool materialise to fetch ``ToolShedRepository`` just so the Tool ctor's ``populate_tool_shed_info`` could stamp four scalar fields. The eager pipeline already has a namedtuple stub for exactly this case (``ToolConfRepository`` in ``lib/galaxy/tool_util/toolbox/base.py:87``, used for shed installs whose install-DB row hasn't appeared yet) — build it directly from ``ToolIndexEntry``. Eliminates: - ``_lookup_tool_shed_repository`` method (~30 lines). - ``galaxy.tool_shed.util.repository_util.get_installed_repository`` module-level import. - A DB round-trip per shed-tool materialise. ``installed_tool_dependencies`` readers see ``tool_dependencies_installed_or_in_error=[]`` for materialised lazy tools — same shape the eager pipeline produces when the install-DB row is missing, so downstream callers already tolerate this. If a job runner ever needs real DB-backed dependency info, it can query ``app.install_model`` directly using the scalar shed metadata already on ``Tool``. 16/16 integration tests still pass.
This commit is contained in:
@@ -36,8 +36,8 @@ from galaxy.exceptions import (
|
||||
ObjectNotFound,
|
||||
RequestParameterInvalidException,
|
||||
)
|
||||
from galaxy.tool_shed.util.repository_util import get_installed_repository
|
||||
from galaxy.tool_util.id_util import extract_short_id_from_guid
|
||||
from galaxy.tool_util.toolbox.base import ToolConfRepository
|
||||
from galaxy.util.tool_version import remove_version_from_guid
|
||||
from galaxy.tool_util.parser import get_tool_source
|
||||
from galaxy.tool_util.toolbox.lineages.interface import ToolLineage
|
||||
@@ -835,50 +835,28 @@ class LazyToolBox(ToolBox):
|
||||
kwds: dict[str, Any] = {"tool_dir": stored.tool_dir}
|
||||
if stored.tool_id and "/repos/" in stored.tool_id:
|
||||
kwds["guid"] = stored.tool_id
|
||||
# Hand the matching ToolShedRepository to the Tool ctor so
|
||||
# ``populate_tool_shed_info`` can stamp ``tool_shed`` /
|
||||
# ``repository_name`` / ``changeset_revision`` /
|
||||
# ``installed_changeset_revision`` onto the Tool. Without
|
||||
# them, ``Tool.to_dict`` skips the ``tool_shed_repository``
|
||||
# block (gated on ``self.tool_shed`` being truthy) and tests
|
||||
# like ``test_only_latest_version_in_panel_fastp`` raise
|
||||
# ``KeyError: 'tool_shed_repository'`` on the rendered
|
||||
# response.
|
||||
shed_repo = self._lookup_tool_shed_repository(stored, entry)
|
||||
if shed_repo is not None:
|
||||
kwds["tool_shed_repository"] = shed_repo
|
||||
# ``ToolConfRepository`` (lib/galaxy/tool_util/toolbox/base.py:87)
|
||||
# is the same namedtuple stub the eager pipeline hands the Tool
|
||||
# ctor for shed tools whose install-DB row hasn't materialised
|
||||
# yet — see ``AbstractToolBox.get_tool_repository_from_xml_item``.
|
||||
# ``Tool.populate_tool_shed_info`` only reads the scalar fields,
|
||||
# all of which are on ``ToolIndexEntry``; building the stub
|
||||
# directly avoids a per-materialise install-DB round-trip.
|
||||
# ``installed_tool_dependencies`` readers get ``[]`` — same
|
||||
# shape the eager pre-install code path produces.
|
||||
if entry and not entry.is_local and entry.tool_shed:
|
||||
kwds["tool_shed_repository"] = ToolConfRepository(
|
||||
tool_shed=entry.tool_shed,
|
||||
name=entry.repository_name,
|
||||
owner=entry.repository_owner,
|
||||
installed_changeset_revision=entry.changeset_revision,
|
||||
changeset_revision=entry.changeset_revision,
|
||||
tool_dependencies_installed_or_in_error=[],
|
||||
repository_path=None,
|
||||
tool_path=stored.tool_dir,
|
||||
)
|
||||
return create_tool_from_source(self.app, tool_source, **kwds)
|
||||
|
||||
def _lookup_tool_shed_repository(self, stored: StoredToolSource, entry: Optional[ToolIndexEntry]) -> Optional[Any]:
|
||||
"""Resolve the installed ToolShedRepository for a stored shed tool.
|
||||
|
||||
Mirrors ``AbstractToolBox.get_tool_repository_from_xml_item`` but
|
||||
sources the tool_shed / repository_name / repository_owner /
|
||||
installed_changeset_revision from the index entry (stamped by
|
||||
``_lazy_register_tool_item`` from the install elem) instead of
|
||||
re-parsing the conf XML.
|
||||
"""
|
||||
if entry is None or entry.is_local:
|
||||
return None
|
||||
tool_shed = entry.tool_shed
|
||||
repo_name = entry.repository_name
|
||||
repo_owner = entry.repository_owner
|
||||
installed_changeset = entry.changeset_revision
|
||||
if not (tool_shed and repo_name and repo_owner and installed_changeset):
|
||||
return None
|
||||
try:
|
||||
return get_installed_repository(
|
||||
self.app,
|
||||
tool_shed=tool_shed,
|
||||
name=repo_name,
|
||||
owner=repo_owner,
|
||||
installed_changeset_revision=installed_changeset,
|
||||
from_cache=True,
|
||||
)
|
||||
except Exception as e:
|
||||
log.debug(f"Lazy lookup of tool_shed_repository for {stored.tool_id} failed: {e}")
|
||||
return None
|
||||
|
||||
def invalidate_index_cache(self) -> None:
|
||||
"""Drop cached tool index so the next read picks up out-of-band updates.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user