Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "run" with singularity/apptainer instead of "exec", when possible #2065

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion cwltool/singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
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()
if v[1] != "apptainer":
return False
return v[0][0] >= 2 or (v[0][0] >= 1 and v[0][1] >= 1)

Check warning on line 83 in cwltool/singularity.py

View check run for this annotation

Codecov / codecov/patch

cwltool/singularity.py#L83

Added line #L83 was not covered by tests


def is_version_2_6() -> bool:
"""
Check if this singularity version is exactly version 2.6.
Expand Down Expand Up @@ -119,6 +127,12 @@
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)


def _normalize_image_id(string: str) -> str:
return string.replace("/", "_") + ".img"

Expand Down Expand Up @@ -464,14 +478,18 @@
) -> tuple[list[str], Optional[str]]:
"""Return the Singularity runtime list of commands and options."""
any_path_okay = self.builder.get_requirement("DockerRequirement")[1] or False

runtime = [
"singularity",
"--quiet",
"exec",
"run" if is_apptainer_1_1_or_newer() or is_version_3_10_or_newer() else "exec",
"--contain",
"--ipc",
"--cleanenv",
]
mr-c marked this conversation as resolved.
Show resolved Hide resolved
if is_apptainer_1_1_or_newer() or is_version_3_10_or_newer():
runtime.append("--no-eval")

if singularity_supports_userns():
runtime.append("--userns")
else:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ 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"
sing_vars["SINGULARITY_NO_EVAL"] = None

result.update(sing_vars)

Expand Down