Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/planemo/engine/factory.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
| author | shellac | 
|---|---|
| date | Thu, 14 May 2020 14:56:58 -0400 | 
| parents | 26e78fe6e8c4 | 
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 1:75ca89e9b81c | 2:6af9afd405e9 | 
|---|---|
| 1 """Module contains factory method for building class:`Engine` objects.""" | |
| 2 | |
| 3 import contextlib | |
| 4 | |
| 5 from .cwltool import CwlToolEngine | |
| 6 from .galaxy import ( | |
| 7 DockerizedManagedGalaxyEngine, | |
| 8 ExternalGalaxyEngine, | |
| 9 LocalManagedGalaxyEngine, | |
| 10 ) | |
| 11 from .toil import ToilEngine | |
| 12 | |
| 13 | |
| 14 UNKNOWN_ENGINE_TYPE_MESSAGE = "Unknown engine type specified [%s]." | |
| 15 | |
| 16 | |
| 17 def is_galaxy_engine(**kwds): | |
| 18 """Return True iff the engine configured is :class:`GalaxyEngine`.""" | |
| 19 engine_type_str = kwds.get("engine", "galaxy") | |
| 20 return engine_type_str in ["galaxy", "docker_galaxy", "external_galaxy"] | |
| 21 | |
| 22 | |
| 23 def build_engine(ctx, **kwds): | |
| 24 """Build an engine from the supplied planemo configuration.""" | |
| 25 engine_type_str = kwds.get("engine", "galaxy") | |
| 26 if engine_type_str == "galaxy": | |
| 27 engine_type = LocalManagedGalaxyEngine | |
| 28 elif engine_type_str == "docker_galaxy": | |
| 29 engine_type = DockerizedManagedGalaxyEngine | |
| 30 elif engine_type_str == "external_galaxy": | |
| 31 engine_type = ExternalGalaxyEngine | |
| 32 elif engine_type_str == "cwltool": | |
| 33 engine_type = CwlToolEngine | |
| 34 elif engine_type_str == "toil": | |
| 35 engine_type = ToilEngine | |
| 36 else: | |
| 37 raise Exception(UNKNOWN_ENGINE_TYPE_MESSAGE % engine_type_str) | |
| 38 | |
| 39 return engine_type(ctx, **kwds) | |
| 40 | |
| 41 | |
| 42 @contextlib.contextmanager | |
| 43 def engine_context(ctx, **kwds): | |
| 44 """A :func:`contextlib.contextmanager` engine builder for use with ``with`` statements. | |
| 45 | |
| 46 https://docs.python.org/2/library/contextlib.html | |
| 47 """ | |
| 48 engine = None | |
| 49 try: | |
| 50 engine = build_engine(ctx, **kwds) | |
| 51 yield engine | |
| 52 finally: | |
| 53 if engine is not None: | |
| 54 engine.cleanup() | |
| 55 | |
| 56 | |
| 57 __all__ = ( | |
| 58 "is_galaxy_engine", | |
| 59 "build_engine", | |
| 60 "engine_context", | |
| 61 ) | 
