Skip to content

Commit

Permalink
switch command if singularity >= 3.10 or apptainer >=1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sameeul authored and mr-c committed Nov 12, 2024
1 parent 199b30c commit 018fb48
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion cwltool/singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def is_apptainer_1_or_newer() -> bool:
return False
return v[0][0] >= 1

def is_apptainer_1_1_or_newer() -> bool:
"""
Check if apptainer singularity distribution is version 1.1 or higher.
"""
v = get_version()

Check warning on line 81 in cwltool/singularity.py

View check run for this annotation

Codecov / codecov/patch

cwltool/singularity.py#L81

Added line #L81 was not covered by tests
if v[1] != "apptainer":
return False
return v[0][0] >= 1 and v[0][1] >= 1

Check warning on line 84 in cwltool/singularity.py

View check run for this annotation

Codecov / codecov/patch

cwltool/singularity.py#L83-L84

Added lines #L83 - L84 were not covered by tests

def is_version_2_6() -> bool:
"""
Expand Down Expand Up @@ -118,6 +126,10 @@ def is_version_3_9_or_newer() -> bool:
v = get_version()
return v[0][0] >= 4 or (v[0][0] == 3 and v[0][1] >= 9)

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

Check warning on line 132 in cwltool/singularity.py

View check run for this annotation

Codecov / codecov/patch

cwltool/singularity.py#L131-L132

Added lines #L131 - L132 were not covered by tests

def _normalize_image_id(string: str) -> str:
return string.replace("/", "_") + ".img"
Expand Down Expand Up @@ -467,11 +479,17 @@ def create_runtime(
runtime = [
"singularity",
"--quiet",
"run",
"--contain",
"--ipc",
"--cleanenv",
]

if is_apptainer_1_1_or_newer() or is_version_3_10_or_newer():
runtime.append("run")
runtime.append("--no-eval")

Check warning on line 489 in cwltool/singularity.py

View check run for this annotation

Codecov / codecov/patch

cwltool/singularity.py#L488-L489

Added lines #L488 - L489 were not covered by tests
else:
runtime.append("exec")

Check warning on line 491 in cwltool/singularity.py

View check run for this annotation

Codecov / codecov/patch

cwltool/singularity.py#L491

Added line #L491 was not covered by tests

if singularity_supports_userns():
runtime.append("--userns")
else:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def PWD(v: str, env: Env) -> bool:
if vminor == 5:
sing_vars["SINGULARITY_INIT"] = "1"
elif vminor > 5:
sing_vars["SINGULARITY_COMMAND"] = "run"
sing_vars["SINGULARITY_COMMAND"] = "exec"
if vminor >= 7:
if vminor > 9:
sing_vars["SINGULARITY_BIND"] = ""
Expand All @@ -159,6 +159,8 @@ def BIND(v: str, env: Env) -> bool:
return v.startswith(tmp_prefix) and v.endswith(":/tmp")

sing_vars["SINGULARITY_BIND"] = BIND
if vminor >= 10:
sing_vars["SINGULARITY_COMMAND"] = "run"

result.update(sing_vars)

Expand Down

0 comments on commit 018fb48

Please sign in to comment.