Skip to content

Commit

Permalink
Move ToolWatcher from Toolbox to ConfigWatchers class
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Apr 3, 2017
1 parent 1a5e337 commit 2515d01
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
7 changes: 5 additions & 2 deletions lib/galaxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from galaxy.sample_tracking import external_service_types
from galaxy.openid.providers import OpenIDProviders
from galaxy.tools.data_manager.manager import DataManagers
from galaxy.tools.toolbox.cache import ToolCache
from galaxy.jobs import metrics as job_metrics
from galaxy.web.proxy import ProxyManager
from galaxy.web.stack import application_stack_instance
Expand Down Expand Up @@ -97,6 +98,10 @@ def __init__( self, **kwargs ):
# Initialize the job management configuration
self.job_config = jobs.JobConfiguration(self)

# Setup a Tool Cache
self.tool_cache = ToolCache()
# Watch various config files for immediate reload
self.watchers = ConfigWatchers(self)
self._configure_toolbox()

# Load Data Manager
Expand All @@ -113,8 +118,6 @@ def __init__( self, **kwargs ):
self.datatypes_registry.load_external_metadata_tool( self.toolbox )
# Load history import/export tools.
load_lib_tools( self.toolbox )
# Watch various config files for immediate reload
self.watchers = ConfigWatchers(self)
# visualizations registry: associates resources with visualizations, controls how to render
self.visualizations_registry = VisualizationsRegistry(
self,
Expand Down
2 changes: 0 additions & 2 deletions lib/galaxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,9 @@ def _configure_toolbox( self ):
from galaxy import tools
from galaxy.managers.citations import CitationsManager
from galaxy.tools.deps import containers
from galaxy.tools.toolbox.cache import ToolCache
from galaxy.tools.toolbox.lineages.tool_shed import ToolVersionCache

self.citations_manager = CitationsManager( self )
self.tool_cache = ToolCache()
self.tool_version_cache = ToolVersionCache(self)

self._toolbox_lock = threading.RLock()
Expand Down
25 changes: 8 additions & 17 deletions lib/galaxy/tools/toolbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
)
from .parser import ensure_tool_conf_item, get_toolbox_parser
from .tags import tool_tag_manager
from .watcher import (
get_tool_watcher
)

log = logging.getLogger( __name__ )

Expand Down Expand Up @@ -73,7 +70,7 @@ def __init__( self, config_filenames, tool_root_dir, app ):
# (e.g., shed_tool_conf.xml) files include the tool_path attribute within the <toolbox> tag.
self._tool_root_dir = tool_root_dir
self.app = app
self._tool_watcher = get_tool_watcher( self, app.config )
self._tool_watcher = self.app.watchers.tool_watcher
self._filter_factory = FilterFactory( self )
self._tool_tag_manager = tool_tag_manager( app )
self._init_tools_from_configs( config_filenames )
Expand Down Expand Up @@ -514,10 +511,14 @@ def _load_tool_tag_set( self, item, panel_dict, integrated_panel_dict, tool_path
path_template = item.get( "file" )
template_kwds = self._path_template_kwds()
path = string.Template(path_template).safe_substitute(**template_kwds)
concrete_path = os.path.join(tool_path, path)
if not os.path.exists(concrete_path):
# This is a lot faster than attempting to load a non-existing tool
raise IOError
tool_shed_repository = None
can_load_into_panel_dict = True

tool = self.load_tool_from_cache(os.path.join(tool_path, path))
tool = self.load_tool_from_cache(concrete_path)
from_cache = tool
if from_cache:
if guid and tool.id != guid:
Expand All @@ -532,9 +533,9 @@ def _load_tool_tag_set( self, item, panel_dict, integrated_panel_dict, tool_path
# Only load tools if the repository is not deactivated or uninstalled.
can_load_into_panel_dict = not tool_shed_repository.deleted
repository_id = self.app.security.encode_id(tool_shed_repository.id)
tool = self.load_tool(os.path.join( tool_path, path ), guid=guid, repository_id=repository_id, use_cached=False)
tool = self.load_tool(concrete_path, guid=guid, repository_id=repository_id, use_cached=False)
if not tool: # tool was not in cache and is not a tool shed tool.
tool = self.load_tool(os.path.join(tool_path, path), use_cached=False)
tool = self.load_tool(concrete_path, use_cached=False)
if string_as_bool(item.get( 'hidden', False )):
tool.hidden = True
key = 'tool_%s' % str(tool.id)
Expand Down Expand Up @@ -918,16 +919,6 @@ def to_dict( self, trans, in_panel=True, **kwds ):

return rval

def shutdown(self):
exception = None
try:
self._tool_watcher.shutdown()
except Exception as e:
exception = e

if exception:
raise exception

def _lineage_in_panel( self, panel_dict, tool=None, tool_lineage=None ):
""" If tool with same lineage already in panel (or section) - find
and return it. Otherwise return None.
Expand Down
21 changes: 14 additions & 7 deletions lib/galaxy/webapps/galaxy/config_watchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
reload_toolbox,
)
from galaxy.tools.toolbox.watcher import (
get_tool_watcher,
get_tool_conf_watcher,
get_tool_data_dir_watcher
)
Expand All @@ -16,6 +17,7 @@ def __init__(self, app):
self.tool_config_watcher = get_tool_conf_watcher(reload_callback=lambda: reload_toolbox(self.app), tool_cache=self.app.tool_cache)
self.data_manager_config_watcher = get_tool_conf_watcher(reload_callback=lambda: reload_data_managers(self.app), tool_cache=self.app.tool_cache)
self.tool_data_watcher = get_tool_data_dir_watcher(self.app.tool_data_tables, config=self.app.config)
self.tool_watcher = get_tool_watcher( self, app.config )
self.start()

def start(self):
Expand All @@ -26,22 +28,27 @@ def start(self):
@property
def data_manager_configs(self):
data_manager_configs = []
data_manager_configs.append(self.app.config.data_manager_config_file)
if self.app.config.shed_data_manager_config_file:
if hasattr(self.app.config, 'data_manager_config_file'):
data_manager_configs.append(self.app.config.data_manager_config_file)
if hasattr(self.app.config, 'shed_data_manager_config_file'):
data_manager_configs.append(self.app.config.shed_data_manager_config_file)
return data_manager_configs

@property
def tool_data_paths(self):
tool_data_paths = []
tool_data_paths.append(self.app.config.tool_data_path)
if self.app.config.shed_tool_data_path:
if hasattr(self.app.config, 'tool_data_path'):
tool_data_paths.append(self.app.config.tool_data_path)
if hasattr(self.app.config, 'shed_tool_data_path'):
tool_data_paths.append(self.app.config.shed_tool_data_path)
return tool_data_paths

@property
def tool_config_paths(self):
tool_config_paths = self.app.config.tool_configs
if self.app.config.migrated_tools_config not in tool_config_paths:
tool_config_paths.append( self.app.config.migrated_tools_config )
tool_config_paths = []
if hasattr(self.app.config, 'tool_configs'):
tool_config_paths = self.app.config.tool_configs
if hasattr(self.app.config, 'self.app.config.migrated_tools_config'):
if self.app.config.migrated_tools_config not in tool_config_paths:
tool_config_paths.append(self.app.config.migrated_tools_config)
return tool_config_paths
2 changes: 2 additions & 0 deletions test/unit/tools/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from galaxy.tools import ToolBox
from galaxy.tools.toolbox.lineages.tool_shed import ToolVersionCache
from galaxy.tools.toolbox.watcher import get_tool_conf_watcher
from galaxy.webapps.galaxy.config_watchers import ConfigWatchers

from .test_toolbox_filters import mock_trans

Expand Down Expand Up @@ -62,6 +63,7 @@ def setUp( self ):
self.app.reindex_tool_search = self.__reindex
itp_config = os.path.join(self.test_directory, "integrated_tool_panel.xml")
self.app.config.integrated_tool_panel_config = itp_config
self.app.watchers = ConfigWatchers(self.app)
self.__toolbox = None
self.config_files = []

Expand Down

0 comments on commit 2515d01

Please sign in to comment.