diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.7/site-packages/planemo/engine/factory.py	Thu May 14 14:56:58 2020 -0400
@@ -0,0 +1,61 @@
+"""Module contains factory method for building class:`Engine` objects."""
+
+import contextlib
+
+from .cwltool import CwlToolEngine
+from .galaxy import (
+    DockerizedManagedGalaxyEngine,
+    ExternalGalaxyEngine,
+    LocalManagedGalaxyEngine,
+)
+from .toil import ToilEngine
+
+
+UNKNOWN_ENGINE_TYPE_MESSAGE = "Unknown engine type specified [%s]."
+
+
+def is_galaxy_engine(**kwds):
+    """Return True iff the engine configured is :class:`GalaxyEngine`."""
+    engine_type_str = kwds.get("engine", "galaxy")
+    return engine_type_str in ["galaxy", "docker_galaxy", "external_galaxy"]
+
+
+def build_engine(ctx, **kwds):
+    """Build an engine from the supplied planemo configuration."""
+    engine_type_str = kwds.get("engine", "galaxy")
+    if engine_type_str == "galaxy":
+        engine_type = LocalManagedGalaxyEngine
+    elif engine_type_str == "docker_galaxy":
+        engine_type = DockerizedManagedGalaxyEngine
+    elif engine_type_str == "external_galaxy":
+        engine_type = ExternalGalaxyEngine
+    elif engine_type_str == "cwltool":
+        engine_type = CwlToolEngine
+    elif engine_type_str == "toil":
+        engine_type = ToilEngine
+    else:
+        raise Exception(UNKNOWN_ENGINE_TYPE_MESSAGE % engine_type_str)
+
+    return engine_type(ctx, **kwds)
+
+
+@contextlib.contextmanager
+def engine_context(ctx, **kwds):
+    """A :func:`contextlib.contextmanager` engine builder for use with ``with`` statements.
+
+    https://docs.python.org/2/library/contextlib.html
+    """
+    engine = None
+    try:
+        engine = build_engine(ctx, **kwds)
+        yield engine
+    finally:
+        if engine is not None:
+            engine.cleanup()
+
+
+__all__ = (
+    "is_galaxy_engine",
+    "build_engine",
+    "engine_context",
+)