@@ -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 )
0 commit comments