11"""Module contianing the :class:`GalaxyEngine` implementation of :class:`Engine`."""
22
3+ import abc
34import contextlib
45
6+ from galaxy .tools .verify .interactor import GalaxyInteractorApi , verify_tool
7+
58from planemo .galaxy .activity import execute
9+ from planemo .galaxy .config import external_galaxy_config
610from planemo .galaxy .serve import serve_daemon
711from planemo .runnable import RunnableType
812from .interface import BaseEngine
913
1014
1115class GalaxyEngine (BaseEngine ):
12- """An :class:`Engine` implementation backed by Galaxy.
16+ """An :class:`Engine` implementation backed by a managed Galaxy.
1317
1418 More information on Galaxy can be found at http://galaxyproject.org/.
1519 """
1620
21+ __metaclass__ = abc .ABCMeta
22+
1723 handled_runnable_types = [
1824 RunnableType .cwl_tool ,
1925 RunnableType .cwl_workflow ,
@@ -24,14 +30,63 @@ class GalaxyEngine(BaseEngine):
2430 def _run (self , runnable , job_path ):
2531 """Run CWL job in Galaxy."""
2632 self ._ctx .vlog ("Serving artifact [%s] with Galaxy." % (runnable ,))
27- with self .serve_runnables ([runnable ]) as config :
33+ with self .ensure_runnables_served ([runnable ]) as config :
2834 self ._ctx .vlog ("Running job path [%s]" % job_path )
2935 run_response = execute (self ._ctx , config , runnable , job_path , ** self ._kwds )
3036
3137 return run_response
3238
39+ @abc .abstractmethod
40+ def ensure_runnables_served (self , runnables ):
41+ """Use a context manager and describe Galaxy instance with runnables being served."""
42+
43+ def _run_test_case (self , test_case ):
44+ if hasattr (test_case , "job_path" ):
45+ # Simple file-based job path.
46+ super (GalaxyEngine , self )._run_test_case (test_case )
47+ else :
48+ with self .ensure_runnables_served ([test_case .runnable ]) as config :
49+ galaxy_interactor_kwds = {
50+ "galaxy_url" : config .galaxy_url ,
51+ "master_api_key" : config .master_api_key ,
52+ "api_key" : config .user_api_key ,
53+ "keep_outputs_dir" : "" , # TODO: this...
54+ }
55+ tool_id = test_case .tool_id
56+ test_index = test_case .test_index
57+ tool_version = test_case .tool_version
58+ galaxy_interactor = GalaxyInteractorApi (** galaxy_interactor_kwds )
59+
60+ test_results = []
61+
62+ def _register_job_data (job_data ):
63+ test_results .append ({
64+ 'id' : tool_id + "-" + str (test_index ),
65+ 'has_data' : True ,
66+ 'data' : job_data ,
67+ })
68+
69+ try :
70+ verify_tool (
71+ tool_id , galaxy_interactor , test_index = test_index , tool_version = tool_version , register_job_data = _register_job_data
72+ )
73+ finally :
74+ pass
75+
76+ # TODO: record pass vs fail
77+ # TODO: record timing
78+ # TODO: return run_response compatible interface maybe?
79+ return test_results [0 ]
80+
81+
82+ class LocalManagedGalaxyEngine (BaseEngine ):
83+ """An :class:`Engine` implementation backed by a managed Galaxy.
84+
85+ More information on Galaxy can be found at http://galaxyproject.org/.
86+ """
87+
3388 @contextlib .contextmanager
34- def serve_runnables (self , runnables ):
89+ def ensure_runnables_served (self , runnables ):
3590 # TODO: define an interface for this - not everything in config would make sense for a
3691 # pre-existing Galaxy interface.
3792 with serve_daemon (self ._ctx , runnables , ** self ._serve_kwds ()) as config :
@@ -41,7 +96,7 @@ def _serve_kwds(self):
4196 return self ._kwds .copy ()
4297
4398
44- class DockerizedGalaxyEngine ( GalaxyEngine ):
99+ class DockerizedManagedGalaxyEngine ( LocalManagedGalaxyEngine ):
45100 """An :class:`Engine` implementation backed by Galaxy running in Docker.
46101
47102 More information on Galaxy can be found at http://galaxyproject.org/.
@@ -53,7 +108,20 @@ def _serve_kwds(self):
53108 return serve_kwds
54109
55110
111+ class ExternalGalaxyEngine (GalaxyEngine ):
112+ """An :class:`Engine` implementation backed by an external Galaxy instance.
113+ """
114+
115+ @contextlib .contextmanager
116+ def ensure_runnables_served (self , runnables ):
117+ # TODO: ensure tools are available
118+ with external_galaxy_config (self ._ctx , runnables , self ._kwds ()) as config :
119+ config .install_workflows ()
120+ yield config
121+
122+
56123__all__ = (
57- "GalaxyEngine" ,
58- "DockerizedGalaxyEngine" ,
124+ "DockerizedManagedGalaxyEngine" ,
125+ "ExternalGalaxyEngine" ,
126+ "LocalManagedGalaxyEngine" ,
59127)
0 commit comments