Skip to content

Commit 0de6e43

Browse files
committed
Fix various bugs/hacks with tool_data_table handling.
These two hacks in tasks and queue_worker are a bit ugly - this is cleaner. We also specify these attributes are available on the protocol for the simpler apps so they should be available without needing to call these configure methods.
1 parent be98011 commit 0de6e43

File tree

10 files changed

+59
-24
lines changed

10 files changed

+59
-24
lines changed

lib/galaxy/app.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,13 @@ class MinimalGalaxyApplication(BasicSharedApp, HaltableContainer, SentryClientMi
266266
container_finder: containers.ContainerFinder
267267
install_model: ModelMapping
268268
object_store: BaseObjectStore
269+
_tool_data_tables: Optional[BaseToolDataTableManager]
270+
_genome_builds: Optional[GenomeBuilds]
269271

270272
def __init__(self, fsmon=False, **kwargs) -> None:
271273
super().__init__()
274+
self._genome_builds = None
275+
self._tool_data_tables = None
272276
self.haltables = [
273277
("object store", self._shutdown_object_store),
274278
("database connection", self._shutdown_model),
@@ -314,7 +318,15 @@ def configure_fluent_log(self):
314318
self.trace_logger = None
315319

316320
def _configure_genome_builds(self, data_table_name="__dbkeys__", load_old_style=True):
317-
self.genome_builds = GenomeBuilds(self, data_table_name=data_table_name, load_old_style=load_old_style)
321+
self._genome_builds = GenomeBuilds(self, data_table_name=data_table_name, load_old_style=load_old_style)
322+
323+
# lazy initialize genome_builds so tool_data_tables is also lazy
324+
@property
325+
def genome_builds(self) -> GenomeBuilds:
326+
if self._genome_builds is None:
327+
self._configure_genome_builds()
328+
assert self._genome_builds is not None
329+
return self._genome_builds
318330

319331
def wait_for_toolbox_reload(self, old_toolbox):
320332
timer = ExecutionTimer()
@@ -412,22 +424,30 @@ def _set_enabled_container_types(self):
412424

413425
def _configure_tool_data_tables(self, from_shed_config):
414426
# Initialize tool data tables using the config defined by self.config.tool_data_table_config_path.
415-
self.tool_data_tables: BaseToolDataTableManager = ToolDataTableManager(
427+
tool_data_tables: BaseToolDataTableManager = ToolDataTableManager(
416428
tool_data_path=self.config.tool_data_path,
417429
config_filename=self.config.tool_data_table_config_path,
418430
other_config_dict=self.config,
419431
)
420432
# Load additional entries defined by self.config.shed_tool_data_table_config into tool data tables.
421433
try:
422-
self.tool_data_tables.load_from_config_file(
434+
tool_data_tables.load_from_config_file(
423435
config_filename=self.config.shed_tool_data_table_config,
424-
tool_data_path=self.tool_data_tables.tool_data_path,
436+
tool_data_path=tool_data_tables.tool_data_path,
425437
from_shed_config=from_shed_config,
426438
)
427439
except OSError as exc:
428440
# Missing shed_tool_data_table_config is okay if it's the default
429441
if exc.errno != errno.ENOENT or self.config.is_set("shed_tool_data_table_config"):
430442
raise
443+
self._tool_data_tables = tool_data_tables
444+
445+
@property
446+
def tool_data_tables(self) -> BaseToolDataTableManager:
447+
if self._tool_data_tables is None:
448+
self._configure_tool_data_tables(from_shed_config=False)
449+
assert self._tool_data_tables is not None
450+
return self._tool_data_tables
431451

432452
def _configure_datatypes_registry(self, use_display_applications=True, use_converters=True):
433453
# Create an empty datatypes registry.
@@ -746,10 +766,9 @@ def __init__(self, **kwargs) -> None:
746766
)
747767
self.api_keys_manager = self._register_singleton(ApiKeyManager)
748768

749-
# Tool Data Tables
769+
# Setup lazy variables
750770
self._configure_tool_data_tables(from_shed_config=False)
751-
# Load dbkey / genome build manager
752-
self._configure_genome_builds(data_table_name="__dbkeys__", load_old_style=True)
771+
self._configure_genome_builds()
753772

754773
# Genomes
755774
self.genomes = self._register_singleton(Genomes)

lib/galaxy/celery/tasks.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@
7171
log = get_logger(__name__)
7272

7373

74-
@lru_cache
75-
def setup_data_table_manager(app):
76-
app._configure_tool_data_tables(from_shed_config=False)
77-
78-
7974
@lru_cache
8075
def cached_create_tool_from_representation(app: MinimalManagerApp, raw_tool_source: str):
8176
return create_tool_from_representation(app=app, raw_tool_source=raw_tool_source, tool_source_class="XmlToolSource")
@@ -448,7 +443,6 @@ def import_data_bundle(
448443
tool_data_file_path: Optional[str] = None,
449444
task_user_id: Optional[int] = None,
450445
):
451-
setup_data_table_manager(app)
452446
if src == "uri":
453447
assert uri
454448
tool_data_import_manager.import_data_bundle_by_uri(config, uri, tool_data_file_path=tool_data_file_path)

lib/galaxy/queue_worker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ def reload_data_managers(app, **kwargs):
204204
reload_timer = util.ExecutionTimer()
205205

206206
log.debug("Executing data managers reload on '%s'", app.config.server_name)
207-
app._configure_tool_data_tables(from_shed_config=False)
208207
reload_tool_data_tables(app)
209208
reload_count = app.data_managers._reload_count + 1
210209
app.data_managers = DataManagers(app, None, reload_count)

lib/galaxy/structured_app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ class BasicSharedApp(Container):
8080
auth_manager: AuthManager
8181
security_agent: Any
8282
quota_agent: QuotaAgent
83-
tool_data_tables: "ToolDataTableManager"
83+
84+
@property
85+
def tool_data_tables(self) -> "ToolDataTableManager":
86+
raise NotImplementedError()
8487

8588
@property
8689
def toolbox(self) -> "ToolBox":
@@ -95,10 +98,13 @@ class MinimalToolApp(Protocol):
9598
config: Any
9699
datatypes_registry: Registry
97100
object_store: BaseObjectStore
98-
tool_data_tables: "ToolDataTableManager"
99101
file_sources: ConfiguredFileSources
100102
security: IdEncodingHelper
101103

104+
@property
105+
def tool_data_tables(self) -> "ToolDataTableManager":
106+
raise NotImplementedError()
107+
102108

103109
class MinimalApp(BasicSharedApp):
104110
is_webapp: bool # is_webapp will be set to true when building WSGI app

lib/galaxy/tool_shed/galaxy_install/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class InstallationTarget(HasToolBox, Protocol[ToolBoxType]):
5656
config: Any
5757
installed_repository_manager: "InstalledRepositoryManager"
5858
_toolbox_lock: threading.RLock
59-
tool_data_tables: ToolDataTableManager
59+
60+
@property
61+
def tool_data_tables(self) -> ToolDataTableManager: ...
6062

6163
def wait_for_toolbox_reload(self, old_toolbox: ToolBoxType) -> None: ...

lib/galaxy/tool_shed/unittest_utils/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def __init__(
222222
config.shed_tools_dir = str(tool_root_dir)
223223
self.watchers = Watchers(self)
224224
self.reload_toolbox()
225-
self.tool_data_tables = ToolDataTableManager(
225+
self._tool_data_tables = ToolDataTableManager(
226226
tool_data_path=self.config.tool_data_path,
227227
config_filename=self.config.shed_tool_data_table_config,
228228
other_config_dict=self.config,
@@ -231,6 +231,10 @@ def __init__(
231231
dependency_dir.mkdir()
232232
self.installed_repository_manager = InstalledRepositoryManager(self)
233233

234+
@property
235+
def tool_data_tables(self) -> ToolDataTableManager:
236+
return self._tool_data_tables
237+
234238
@property
235239
def tool_dependency_dir(self) -> Optional[str]:
236240
return None

lib/galaxy/tool_util/parser/output_actions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class ToolOutputActionAppConfig(Protocol):
2727

2828

2929
class ToolOutputActionApp(Protocol):
30-
tool_data_tables: Any # TODO after refactor "ToolDataTableManager"
30+
@property
31+
def tool_data_tables(self) -> Any: ... # TODO after refactor "ToolDataTableManager"
3132

3233
@property
3334
def config(self) -> ToolOutputActionAppConfig: ... # https://github.com/python/mypy/issues/7041

lib/galaxy/tools/remote_tool_eval.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ def __init__(
6666
self.datatypes_registry = datatypes_registry
6767
self.object_store = object_store
6868
self.genome_builds = GenomeBuilds(self)
69-
self.tool_data_tables = tool_data_table_manager
69+
self._tool_data_tables = tool_data_table_manager
7070
self.file_sources = file_sources
7171
self.biotools_metadata_source = None
7272
self.security = None # type: ignore[assignment]
7373

74+
@property
75+
def tool_data_tables(self) -> ToolDataTableManager:
76+
return self._tool_data_tables
77+
7478

7579
def main(TMPDIR, WORKING_DIRECTORY, IMPORT_STORE_DIRECTORY) -> None:
7680
metadata_params = get_metadata_params(WORKING_DIRECTORY)

lib/tool_shed/structured_app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from galaxy.structured_app import BasicSharedApp
44

55
if TYPE_CHECKING:
6-
from galaxy.tools.data import ToolDataTableManager
76
from tool_shed.managers.model_cache import ModelCache
87
from tool_shed.repository_registry import RegistryInterface
98
from tool_shed.repository_types.registry import Registry as RepositoryTypesRegistry
@@ -19,4 +18,3 @@ class ToolShedApp(BasicSharedApp):
1918
hgweb_config_manager: "HgWebConfigManager"
2019
security_agent: "CommunityRBACAgent"
2120
model_cache: "ModelCache"
22-
tool_data_tables: "ToolDataTableManager"

lib/tool_shed/webapp/app.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def __init__(self, **kwd) -> None:
8888
self.tag_handler = CommunityTagHandler(self.model.context)
8989
# Initialize the Tool Shed tool data tables. Never pass a configuration file here
9090
# because the Tool Shed should always have an empty dictionary!
91-
self.tool_data_tables = galaxy.tools.data.ToolDataTableManager(self.config.tool_data_path)
92-
self.genome_builds = GenomeBuilds(self)
91+
self._tool_data_tables = galaxy.tools.data.ToolDataTableManager(self.config.tool_data_path)
92+
self._genome_builds = GenomeBuilds(self)
9393
self.auth_manager = self._register_singleton(auth.AuthManager, auth.AuthManager(self.config))
9494
# Citation manager needed to load tools.
9595
self.citations_manager = self._register_singleton(CitationsManager, CitationsManager(self))
@@ -115,6 +115,14 @@ def __init__(self, **kwd) -> None:
115115
self.server_starttime = int(time.time())
116116
log.debug("Tool shed hgweb.config file is: %s", self.hgweb_config_manager.hgweb_config)
117117

118+
@property
119+
def tool_data_tables(self) -> galaxy.tools.data.ToolDataTableManager:
120+
return self._tool_data_tables
121+
122+
@property
123+
def genome_builds(self) -> GenomeBuilds:
124+
return self._genome_builds
125+
118126

119127
# Global instance of the universe app.
120128
app: Optional[ToolShedApp] = None

0 commit comments

Comments
 (0)