Skip to content

Commit 4a1cc3d

Browse files
committed
switch command if singularity >= 3.10 or apptainer >=1.1
1 parent efdbb01 commit 4a1cc3d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cwltool/singularity.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ def is_apptainer_1_or_newer() -> bool:
7474
return False
7575
return v[0][0] >= 1
7676

77+
def is_apptainer_1_1_or_newer() -> bool:
78+
"""
79+
Check if apptainer singularity distribution is version 1.1 or higher.
80+
"""
81+
v = get_version()
82+
if v[1] != "apptainer":
83+
return False
84+
return v[0][0] >= 1 and v[0][1] >= 1
7785

7886
def is_version_2_6() -> bool:
7987
"""
@@ -118,6 +126,10 @@ def is_version_3_9_or_newer() -> bool:
118126
v = get_version()
119127
return v[0][0] >= 4 or (v[0][0] == 3 and v[0][1] >= 9)
120128

129+
def is_version_3_10_or_newer() -> bool:
130+
"""Detect if Singularity v3.10+ is available."""
131+
v = get_version()
132+
return v[0][0] >= 4 or (v[0][0] == 3 and v[0][1] >= 10)
121133

122134
def _normalize_image_id(string: str) -> str:
123135
return string.replace("/", "_") + ".img"
@@ -467,11 +479,17 @@ def create_runtime(
467479
runtime = [
468480
"singularity",
469481
"--quiet",
470-
"run",
471482
"--contain",
472483
"--ipc",
473484
"--cleanenv",
474485
]
486+
487+
if is_apptainer_1_1_or_newer() or is_version_3_10_or_newer():
488+
runtime.append("run")
489+
runtime.append("--no-eval")
490+
else:
491+
runtime.append("exec")
492+
475493
if singularity_supports_userns():
476494
runtime.append("--userns")
477495
else:

tests/test_environment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def PWD(v: str, env: Env) -> bool:
149149
if vminor == 5:
150150
sing_vars["SINGULARITY_INIT"] = "1"
151151
elif vminor > 5:
152-
sing_vars["SINGULARITY_COMMAND"] = "run"
152+
sing_vars["SINGULARITY_COMMAND"] = "exec"
153153
if vminor >= 7:
154154
if vminor > 9:
155155
sing_vars["SINGULARITY_BIND"] = ""
@@ -159,6 +159,8 @@ 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"
162164

163165
result.update(sing_vars)
164166

0 commit comments

Comments
 (0)