@@ -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+
7886def 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+
122136def _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 :
0 commit comments