From 8c44fce0c9941cb31d6df1dd67f31f61f5218242 Mon Sep 17 00:00:00 2001 From: cat-bro Date: Thu, 21 Apr 2022 13:36:42 +1000 Subject: [PATCH] pass app.toolbox from reindex_tool_function instead of using stored toolbox --- lib/galaxy/app.py | 2 +- lib/galaxy/tools/search/__init__.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/app.py b/lib/galaxy/app.py index f80c7b131cf9..23a3b9968ecb 100644 --- a/lib/galaxy/app.py +++ b/lib/galaxy/app.py @@ -230,7 +230,7 @@ def _configure_toolbox(self): def reindex_tool_search(self): # Call this when tools are added or removed. - self.toolbox_search.build_index(tool_cache=self.tool_cache) + self.toolbox_search.build_index(tool_cache=self.tool_cache, toolbox=self.toolbox) self.tool_cache.reset_status() def _set_enabled_container_types(self): diff --git a/lib/galaxy/tools/search/__init__.py b/lib/galaxy/tools/search/__init__.py index a324321e9e91..3ca385f27687 100644 --- a/lib/galaxy/tools/search/__init__.py +++ b/lib/galaxy/tools/search/__init__.py @@ -63,7 +63,7 @@ def __init__(self, toolbox, index_dir: str, index_help: bool = True): for panel_view in toolbox.panel_views(): panel_view_id = panel_view.id panel_index_dir = os.path.join(index_dir, panel_view_id) - panel_searches[panel_view_id] = ToolPanelViewSearch(toolbox, panel_view_id, panel_index_dir, index_help=index_help) + panel_searches[panel_view_id] = ToolPanelViewSearch(panel_view_id, panel_index_dir, index_help=index_help) self.panel_searches = panel_searches # We keep track of how many times the tool index has been rebuilt. # We start at -1, so that after the first index the count is at 0, @@ -71,10 +71,10 @@ def __init__(self, toolbox, index_dir: str, index_help: bool = True): # reindexing if the index count is equal to the toolbox reload count. self.index_count = -1 - def build_index(self, tool_cache, index_help: bool = True) -> None: + def build_index(self, tool_cache, toolbox, index_help: bool = True) -> None: self.index_count += 1 for panel_search in self.panel_searches.values(): - panel_search.build_index(tool_cache, index_help=index_help) + panel_search.build_index(tool_cache, toolbox, index_help=index_help) def search(self, *args, **kwd) -> List[str]: panel_view = kwd.pop("panel_view") @@ -90,7 +90,7 @@ class ToolPanelViewSearch: the Whoosh search library. """ - def __init__(self, toolbox, panel_view_id: str, index_dir: str, index_help: bool = True): + def __init__(self, panel_view_id: str, index_dir: str, index_help: bool = True): self.schema = Schema(id=ID(stored=True, unique=True), old_id=ID, stub=KEYWORD, @@ -101,14 +101,13 @@ def __init__(self, toolbox, panel_view_id: str, index_dir: str, index_help: bool labels=KEYWORD) self.rex = analysis.RegexTokenizer() self.index_dir = index_dir - self.toolbox = toolbox self.panel_view_id = panel_view_id self.index = self._index_setup() def _index_setup(self) -> index.Index: return get_or_create_index(index_dir=self.index_dir, schema=self.schema) - def build_index(self, tool_cache, index_help: bool = True) -> None: + def build_index(self, tool_cache, toolbox, index_help: bool = True) -> None: """ Prepare search index for tools loaded in toolbox. Use `tool_cache` to determine which tools need indexing and which tools should be expired. @@ -132,8 +131,8 @@ def build_index(self, tool_cache, index_help: bool = True) -> None: for tool_id in tool_ids_to_remove: writer.delete_by_term('id', tool_id) for tool_id in tool_cache._new_tool_ids - indexed_tool_ids: - tool = self.toolbox.get_tool(tool_id) - if tool and tool.is_latest_version and self.toolbox.panel_has_tool(tool, self.panel_view_id): + tool = toolbox.get_tool(tool_id) + if tool and tool.is_latest_version and toolbox.panel_has_tool(tool, self.panel_view_id): if tool.hidden: # we check if there is an older tool we can return if tool.lineage: