Skip to content

Commit 1557c8d

Browse files
sameeulmr-c
andcommitted
Use "run" with singularity/apptainer instead of "exec", when possible
Co-authored-by: Michael R. Crusoe <1330696+mr-c@users.noreply.github.com>
1 parent 048eb55 commit 1557c8d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cwltool/singularity.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def is_apptainer_1_or_newer() -> bool:
7575
return v[0][0] >= 1
7676

7777

78+
def is_apptainer_1_1_or_newer() -> bool:
79+
"""Check if apptainer singularity distribution is version 1.1 or higher."""
80+
v = get_version()
81+
if v[1] != "apptainer":
82+
return False
83+
return v[0][0] >= 2 or (v[0][0] >= 1 and v[0][1] >= 1)
84+
85+
7886
def is_version_2_6() -> bool:
7987
"""
8088
Check if this singularity version is exactly version 2.6.
@@ -119,6 +127,12 @@ def is_version_3_9_or_newer() -> bool:
119127
return v[0][0] >= 4 or (v[0][0] == 3 and v[0][1] >= 9)
120128

121129

130+
def is_version_3_10_or_newer() -> bool:
131+
"""Detect if Singularity v3.10+ is available."""
132+
v = get_version()
133+
return v[0][0] >= 4 or (v[0][0] == 3 and v[0][1] >= 10)
134+
135+
122136
def _normalize_image_id(string: str) -> str:
123137
return string.replace("/", "_") + ".img"
124138

@@ -464,14 +478,18 @@ def create_runtime(
464478
) -> tuple[list[str], Optional[str]]:
465479
"""Return the Singularity runtime list of commands and options."""
466480
any_path_okay = self.builder.get_requirement("DockerRequirement")[1] or False
481+
467482
runtime = [
468483
"singularity",
469484
"--quiet",
470-
"exec",
485+
"run" if is_apptainer_1_1_or_newer() or is_version_3_10_or_newer() else "exec",
471486
"--contain",
472487
"--ipc",
473488
"--cleanenv",
474489
]
490+
if is_apptainer_1_1_or_newer() or is_version_3_10_or_newer():
491+
runtime.append("--no-eval")
492+
475493
if singularity_supports_userns():
476494
runtime.append("--userns")
477495
else:

tests/test_environment.py

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def BIND(v: str, env: Env) -> bool:
159159
return v.startswith(tmp_prefix) and v.endswith(":/tmp")
160160

161161
sing_vars["SINGULARITY_BIND"] = BIND
162+
if vminor >= 10:
163+
sing_vars["SINGULARITY_COMMAND"] = "run"
164+
sing_vars["SINGULARITY_NO_EVAL"] = None
162165

163166
result.update(sing_vars)
164167

0 commit comments

Comments
 (0)