Skip to content

Commit

Permalink
Merge c7d0a56 into 07dc6e0
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Feb 8, 2019
2 parents 07dc6e0 + c7d0a56 commit ea0f727
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 26 deletions.
2 changes: 1 addition & 1 deletion planemo/commands/cmd_test.py
Expand Up @@ -79,7 +79,7 @@ def cli(ctx, paths, **kwds):
kwds["engine"] = "galaxy" if not is_cwl else "cwltool"

engine_type = kwds["engine"]
enable_test_engines = any([r.type not in [RunnableType.galaxy_tool, RunnableType.directory] for r in runnables])
enable_test_engines = any([r.type not in [RunnableType.galaxy_tool, RunnableType.galaxy_datamanager, RunnableType.directory] for r in runnables])
enable_test_engines = enable_test_engines or engine_type != "galaxy"
if enable_test_engines:
ctx.vlog("Using test engine type %s" % engine_type)
Expand Down
3 changes: 2 additions & 1 deletion planemo/engine/galaxy.py
Expand Up @@ -25,7 +25,8 @@ class GalaxyEngine(BaseEngine):
RunnableType.cwl_tool,
RunnableType.cwl_workflow,
RunnableType.galaxy_workflow,
RunnableType.galaxy_tool
RunnableType.galaxy_tool,
RunnableType.galaxy_datamanager,
]

def _run(self, runnable, job_path):
Expand Down
36 changes: 19 additions & 17 deletions planemo/galaxy/config.py
Expand Up @@ -234,8 +234,7 @@ def simple_docker_volume(path):
@contextlib.contextmanager
def docker_galaxy_config(ctx, runnables, for_tests=False, **kwds):
"""Set up a ``GalaxyConfig`` for Docker container."""
tool_paths = [r.path for r in runnables if r.has_tools]
test_data_dir = _find_test_data(tool_paths, **kwds)
test_data_dir = _find_test_data(runnables, **kwds)

with _config_directory(ctx, **kwds) as config_directory:
def config_join(*args):
Expand Down Expand Up @@ -332,13 +331,13 @@ def config_join(*args):
@contextlib.contextmanager
def local_galaxy_config(ctx, runnables, for_tests=False, **kwds):
"""Set up a ``GalaxyConfig`` in an auto-cleaned context."""
tool_paths = [r.path for r in runnables if r.has_tools]
test_data_dir = _find_test_data(tool_paths, **kwds)
test_data_dir = _find_test_data(runnables, **kwds)
tool_data_table = _find_tool_data_table(
tool_paths,
runnables,
test_data_dir=test_data_dir,
**kwds
)
data_manager_config_paths = [r.data_manager_conf_path for r in runnables if r.data_manager_conf_path]
galaxy_root = _find_galaxy_root(ctx, **kwds)
install_galaxy = kwds.get("install_galaxy", False)
if galaxy_root is not None:
Expand Down Expand Up @@ -454,6 +453,7 @@ def config_join(*args):
watch_tools="auto",
default_job_shell="/bin/bash", # For conda dependency resolution
tool_data_table_config_path=tool_data_table,
data_manager_config_file=",".join(data_manager_config_paths),
integrated_tool_panel_config=("${temp_directory}/"
"integrated_tool_panel_conf.xml"),
# Use in-memory database for kombu to avoid database contention
Expand Down Expand Up @@ -523,7 +523,7 @@ def config_join(*args):


def _all_tool_paths(runnables, **kwds):
tool_paths = [r.path for r in runnables if r.has_tools]
tool_paths = [r.path for r in runnables if r.has_tools and not r.data_manager_conf_path]
all_tool_paths = list(tool_paths) + list(kwds.get("extra_tools", []))
for runnable in runnables:
if runnable.type.name == "galaxy_workflow":
Expand Down Expand Up @@ -1106,39 +1106,41 @@ def _find_galaxy_root(ctx, **kwds):
return None


def _find_test_data(tool_paths, **kwds):
path = "."
if len(tool_paths) > 0:
path = tool_paths[0]
def _find_test_data(runnables, **kwds):
test_data_search_path = "."
runnables = [r for r in runnables if r.has_tools]
if len(runnables) > 0:
test_data_search_path = runnables[0].test_data_search_path

# Find test data directory associated with path.
test_data = kwds.get("test_data", None)
if test_data:
return os.path.abspath(test_data)
else:
test_data = _search_tool_path_for(path, "test-data")
test_data = _search_tool_path_for(test_data_search_path, "test-data")
if test_data:
return test_data
warn(NO_TEST_DATA_MESSAGE)
return None


def _find_tool_data_table(tool_paths, test_data_dir, **kwds):
path = "."
if len(tool_paths) > 0:
path = tool_paths[0]
def _find_tool_data_table(runnables, test_data_dir, **kwds):
tool_data_search_path = "."
runnables = [r for r in runnables if r.has_tools]
if len(runnables) > 0:
tool_data_search_path = runnables[0].tool_data_search_path

tool_data_table = kwds.get("tool_data_table", None)
if tool_data_table:
return os.path.abspath(tool_data_table)
else:
extra_paths = [test_data_dir] if test_data_dir else []
return _search_tool_path_for(
path,
tool_data_search_path,
"tool_data_table_conf.xml.test",
extra_paths,
) or _search_tool_path_for( # if all else fails just use sample
path,
tool_data_search_path,
"tool_data_table_conf.xml.sample"
)

Expand Down
46 changes: 39 additions & 7 deletions planemo/runnable.py
Expand Up @@ -13,6 +13,7 @@
from galaxy.tools.loader_directory import (
is_a_yaml_with_class,
looks_like_a_cwl_artifact,
looks_like_a_data_manager_xml,
looks_like_a_tool_cwl,
looks_like_a_tool_xml,
)
Expand All @@ -35,24 +36,57 @@


RunnableType = aenum.Enum(
"RunnableType", 'galaxy_tool galaxy_workflow cwl_tool cwl_workflow directory'
"RunnableType", 'galaxy_tool galaxy_datamanager galaxy_workflow cwl_tool cwl_workflow directory'
)


@property
def _runnable_type_has_tools(runnable_type):
return runnable_type.name in ["galaxy_tool", "cwl_tool", "directory"]
return runnable_type.name in ["galaxy_tool", "galaxy_datamanager", "cwl_tool", "directory"]


@property
def _runnable_type_is_single_artifact(runnable_type):
return runnable_type.name not in ["directory"]


@property
def _runnable_type_test_data_in_parent_dir(runnable_type):
return runnable_type.name in ["galaxy_datamanager"]


RunnableType.has_tools = _runnable_type_has_tools
RunnableType.is_single_artifact = _runnable_type_is_single_artifact
RunnableType.test_data_in_parent_dir = _runnable_type_test_data_in_parent_dir

_Runnable = collections.namedtuple("Runnable", ["path", "type"])


class Runnable(_Runnable):

@property
def test_data_search_path(self):
if self.type.name in ['galaxy_datamanager']:
return os.path.join(os.path.dirname(self.path), os.path.pardir)
else:
return self.path

Runnable = collections.namedtuple("Runnable", ["path", "type"])
@property
def tool_data_search_path(self):
return self.test_data_search_path

@property
def data_manager_conf_path(self):
if self.type.name in ['galaxy_datamanager']:
return os.path.join(os.path.dirname(self.path), os.pardir, 'data_manager_conf.xml')

@property
def has_tools(self):
return _runnable_delegate_attribute('has_tools')

@property
def is_single_artifact(self):
return _runnable_delegate_attribute('is_single_artifact')


def _runnable_delegate_attribute(attribute):
Expand All @@ -64,17 +98,15 @@ def getter(runnable):
return getter


Runnable.has_tools = _runnable_delegate_attribute('has_tools')
Runnable.is_single_artifact = _runnable_delegate_attribute('is_single_artifact')


def for_path(path):
"""Produce a class:`Runnable` for supplied path."""
runnable_type = None
if os.path.isdir(path):
runnable_type = RunnableType.directory
elif looks_like_a_tool_cwl(path):
runnable_type = RunnableType.cwl_tool
elif looks_like_a_data_manager_xml:
runnable_type = RunnableType.galaxy_datamanager
elif looks_like_a_tool_xml(path):
runnable_type = RunnableType.galaxy_tool
elif is_a_yaml_with_class(path, ["GalaxyWorkflow"]):
Expand Down

0 comments on commit ea0f727

Please sign in to comment.