Skip to content

Commit 388732f

Browse files
add support for running tools with singularity
1 parent e8d0fd2 commit 388732f

File tree

2 files changed

+99
-49
lines changed

2 files changed

+99
-49
lines changed

planemo/galaxy/config.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828

2929
from galaxy.tool_util.deps import docker_util
30+
from galaxy.tool_util.deps import singularity_util
3031
from galaxy.tool_util.deps.container_volumes import DockerVolume
3132
from galaxy.util.commands import argv_to_str
3233
from galaxy.util.yaml_util import ordered_dump
@@ -117,11 +118,6 @@
117118
"planemo_dest": {
118119
"runner": "planemo_runner",
119120
"require_container": False,
120-
"docker_enabled": False,
121-
"docker_sudo": False,
122-
"docker_sudo_cmd": docker_util.DEFAULT_SUDO_COMMAND,
123-
"docker_cmd": docker_util.DEFAULT_DOCKER_COMMAND,
124-
"docker_volumes": "$defaults",
125121
},
126122
"upload_dest": {"runner": "planemo_runner", "docker_enabled": False},
127123
},
@@ -325,11 +321,14 @@ def local_galaxy_config(ctx, runnables, for_tests=False, **kwds):
325321

326322
# Duplicate block in docker variant above.
327323
if kwds.get("mulled_containers", False):
328-
if not kwds.get("docker", False):
329-
if ctx.get_option_source("docker") != OptionSource.cli:
324+
if not (kwds.get("docker", False) or kwds.get("singularity", False)):
325+
if (
326+
ctx.get_option_source("docker") != OptionSource.cli
327+
and ctx.get_option_source("singularity") != OptionSource.cli
328+
):
330329
kwds["docker"] = True
331330
else:
332-
raise Exception("Specified no docker and mulled containers together.")
331+
raise Exception("Specified --no-docker/--no-singularity and mulled containers together.")
333332
conda_default_options = ("conda_auto_init", "conda_auto_install")
334333
use_conda_options = ("dependency_resolution", "conda_use_local", "conda_prefix", "conda_exec")
335334
if not any(kwds.get(_) for _ in use_conda_options) and all(
@@ -709,7 +708,7 @@ class GalaxyConfig(GalaxyInterface, metaclass=abc.ABCMeta):
709708
710709
This assumes more than an API connection is available - Planemo needs to be able to
711710
start and stop the Galaxy instance, recover logs, etc... There are currently two
712-
implementations - a locally executed Galaxy and one running inside a Docker containe
711+
implementations - a locally executed Galaxy and one running inside a Docker container
713712
"""
714713

715714
@abc.abstractproperty
@@ -1322,26 +1321,43 @@ def _handle_job_config_file(
13221321
"job_conf.yml",
13231322
)
13241323
planemo_dest = JOB_CONFIG_LOCAL["execution"]["environments"]["planemo_dest"]
1325-
planemo_dest["docker_enabled"] = kwds.get("docker", False)
1326-
planemo_dest["docker_sudo"] = kwds.get("docker_sudo", False)
1327-
planemo_dest["docker_sudo_cmd"] = kwds.get("docker_sudo_cmd", docker_util.DEFAULT_SUDO_COMMAND)
1328-
planemo_dest["docker_cmd"] = kwds.get("docker_cmd", docker_util.DEFAULT_DOCKER_COMMAND)
1329-
1330-
docker_host = kwds.get("docker_host", docker_util.DEFAULT_HOST)
1331-
if docker_host:
1332-
planemo_dest["docker_host"] = docker_host
1333-
1334-
volumes = list(kwds.get("docker_extra_volume") or [])
1335-
if test_data_dir:
1336-
volumes.append(f"{test_data_dir}:ro")
1337-
1338-
docker_volumes_str = "$defaults"
1339-
if volumes:
1340-
# exclude tool directories, these are mounted :ro by $defaults
1341-
all_tool_dirs = {os.path.dirname(tool_path) for tool_path in all_tool_paths}
1342-
extra_volumes_str = ",".join(str(v) for v in create_docker_volumes(volumes) if v.path not in all_tool_dirs)
1343-
docker_volumes_str = f"{docker_volumes_str},{extra_volumes_str}"
1344-
planemo_dest["docker_volumes"] = docker_volumes_str
1324+
1325+
for container_type in ["docker", "singularity"]:
1326+
if not kwds.get(container_type, False):
1327+
continue
1328+
planemo_dest[f"{container_type}_enabled"] = kwds.get(container_type, False)
1329+
planemo_dest[f"{container_type}_sudo"] = kwds.get(f"{container_type}_sudo", False)
1330+
planemo_dest[f"{container_type}_sudo_cmd"] = kwds.get(
1331+
f"{container_type}_sudo_cmd",
1332+
docker_util.DEFAULT_SUDO_COMMAND
1333+
if container_type == "docker"
1334+
else singularity_util.DEFAULT_SUDO_COMMAND,
1335+
)
1336+
planemo_dest[f"{container_type}_cmd"] = kwds.get(
1337+
f"{container_type}_cmd",
1338+
docker_util.DEFAULT_DOCKER_COMMAND
1339+
if container_type == "docker"
1340+
else singularity_util.DEFAULT_SINGULARITY_COMMAND,
1341+
)
1342+
if container_type == "docker":
1343+
docker_host = kwds.get("docker_host", docker_util.DEFAULT_HOST)
1344+
if docker_host:
1345+
planemo_dest["docker_host"] = docker_host
1346+
1347+
volumes = list(kwds.get(f"{container_type}_extra_volume") or [])
1348+
if test_data_dir:
1349+
volumes.append(f"{test_data_dir}:ro")
1350+
volumes_str = "$defaults"
1351+
if volumes:
1352+
# exclude tool directories, these are mounted :ro by $defaults
1353+
all_tool_dirs = {os.path.dirname(tool_path) for tool_path in all_tool_paths}
1354+
extra_volumes_str = ",".join(
1355+
str(v) for v in create_docker_volumes(volumes) if v.path not in all_tool_dirs
1356+
)
1357+
volumes_str = f"{volumes_str},{extra_volumes_str}"
1358+
planemo_dest[f"{container_type}_volumes"] = volumes_str
1359+
break
1360+
13451361
JOB_CONFIG_LOCAL["execution"]["environments"]["planemo_dest"] = planemo_dest
13461362
with open(job_config_file, "w") as job_config_fh:
13471363
ordered_dump(JOB_CONFIG_LOCAL, job_config_fh)

planemo/options.py

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import os
66

77
import click
8-
from galaxy.tool_util.deps import docker_util
8+
from galaxy.tool_util.deps import (
9+
docker_util,
10+
singularity_util,
11+
)
912
from galaxy.tool_util.verify.interactor import DEFAULT_TOOL_TEST_WAIT
1013

1114
from .config import planemo_option
@@ -418,7 +421,7 @@ def mulled_containers_option():
418421
"--mulled_containers",
419422
"--biocontainers",
420423
is_flag=True,
421-
help="Test tools against mulled containers (forces --docker). Disables conda resolution unless any conda option has been set explicitly.",
424+
help="Test tools against mulled containers (requires --docker/--singularity, if none of these are given --docker is used automatically). Disables conda resolution unless any conda option has been set explicitly.",
422425
)
423426

424427

@@ -458,13 +461,23 @@ def docker_extra_volume_option():
458461
readable=True,
459462
resolve_path=True,
460463
)
461-
return planemo_option(
462-
"--docker_extra_volume",
463-
type=arg_type,
464-
default=None,
465-
use_global_config=True,
466-
multiple=True,
467-
help=("Extra path to mount if --engine docker or `--biocontainers` or `--docker`."),
464+
return _compose(
465+
planemo_option(
466+
"--docker_extra_volume",
467+
type=arg_type,
468+
default=None,
469+
use_global_config=True,
470+
multiple=True,
471+
help=("Extra path to mount if --engine docker or `--biocontainers` or `--docker`."),
472+
),
473+
planemo_option(
474+
"--singularity_extra_volume",
475+
type=arg_type,
476+
default=None,
477+
use_global_config=True,
478+
multiple=True,
479+
help=("Extra path to mount if `--biocontainers` and `--singularity`."),
480+
)
468481
)
469482

470483

@@ -914,27 +927,48 @@ def no_cleanup_option():
914927

915928

916929
def docker_enable_option():
917-
return planemo_option("--docker/--no_docker", default=False, help=("Run Galaxy tools in Docker if enabled."))
930+
return _compose(
931+
planemo_option("--docker/--no_docker", default=False, help=("Run Galaxy tools in Docker if enabled.")),
932+
planemo_option("--singularity/--no_singularity", default=False, help=("Run Galaxy tools in Singularity if enabled."))
933+
)
918934

919935

920936
def docker_cmd_option():
921-
return planemo_option(
922-
"--docker_cmd",
923-
default=docker_util.DEFAULT_DOCKER_COMMAND,
924-
help="Command used to launch docker (defaults to docker).",
937+
return _compose(
938+
planemo_option(
939+
"--docker_cmd",
940+
default=docker_util.DEFAULT_DOCKER_COMMAND,
941+
help=f"Command used to launch docker (defaults to {docker_util.DEFAULT_DOCKER_COMMAND}).",
942+
),
943+
planemo_option(
944+
"--singularity_cmd",
945+
default=singularity_util.DEFAULT_SINGULARITY_COMMAND,
946+
help=f"Command used to launch singularity (defaults to {singularity_util.DEFAULT_SINGULARITY_COMMAND}).",
947+
)
925948
)
926949

927950

928951
def docker_sudo_option():
929-
return planemo_option("--docker_sudo/--no_docker_sudo", is_flag=True, help="Flag to use sudo when running docker.")
952+
return _compose(
953+
planemo_option("--docker_sudo/--no_docker_sudo", is_flag=True, help="Flag to use sudo when running docker."),
954+
planemo_option("--singularity_sudo/--no_singularity_sudo", is_flag=True, help="Flag to use sudo when running singularity.")
955+
)
930956

931957

932958
def docker_sudo_cmd_option():
933-
return planemo_option(
934-
"--docker_sudo_cmd",
935-
help="sudo command to use when --docker_sudo is enabled " + "(defaults to sudo).",
936-
default=docker_util.DEFAULT_SUDO_COMMAND,
937-
use_global_config=True,
959+
return _compose(
960+
planemo_option(
961+
"--docker_sudo_cmd",
962+
help=f"sudo command to use when --docker_sudo is enabled (defaults to {docker_util.DEFAULT_SUDO_COMMAND}).",
963+
default=docker_util.DEFAULT_SUDO_COMMAND,
964+
use_global_config=True,
965+
),
966+
planemo_option(
967+
"--singularity_sudo_cmd",
968+
help=f"sudo command to use when --singularity_sudo is enabled (defaults to {singularity_util.DEFAULT_SUDO_COMMAND}).",
969+
default=docker_util.DEFAULT_SUDO_COMMAND,
970+
use_global_config=True,
971+
)
938972
)
939973

940974

0 commit comments

Comments
 (0)