66import os .path
77import re
88import shutil
9- import subprocess
109import sys
1110from collections .abc import Callable , MutableMapping
12- from subprocess import DEVNULL , check_call , check_output , run # nosec
11+ from subprocess import check_call , check_output , run # nosec
1312from typing import cast
1413
1514from schema_salad .sourceline import SourceLine
@@ -146,6 +145,7 @@ def _normalize_sif_id(string: str) -> str:
146145 string += "_latest"
147146 return string .replace ("/" , "_" ) + ".sif"
148147
148+
149149def _inspect_singularity_image (path : str ) -> bool :
150150 """Inspect singularity image to be sure it is not an empty directory."""
151151 cmd = [
@@ -158,16 +158,17 @@ def _inspect_singularity_image(path: str) -> bool:
158158 result = run (cmd , capture_output = True , text = True )
159159 except Exception :
160160 return False
161-
161+
162162 if result .returncode == 0 :
163163 try :
164164 output = json .loads (result .stdout )
165165 except json .JSONDecodeError :
166166 return False
167- if output .get (' data' , {}).get (' attributes' , {}):
167+ if output .get (" data" , {}).get (" attributes" , {}):
168168 return True
169169 return False
170170
171+
171172class SingularityCommandLineJob (ContainerCommandLineJob ):
172173 def __init__ (
173174 self ,
@@ -253,7 +254,9 @@ def get_image(
253254 found = True
254255 elif "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement :
255256 # looking for local singularity sandbox image and handle it as a local image
256- if os .path .isdir (dockerRequirement ["dockerPull" ]) and _inspect_singularity_image (dockerRequirement ["dockerPull" ]):
257+ if os .path .isdir (dockerRequirement ["dockerPull" ]) and _inspect_singularity_image (
258+ dockerRequirement ["dockerPull" ]
259+ ):
257260 dockerRequirement ["dockerImageId" ] = dockerRequirement ["dockerPull" ]
258261 _logger .info (
259262 "Using local Singularity sandbox image found in %s" ,
@@ -280,7 +283,9 @@ def get_image(
280283 if is_version_3_or_newer ():
281284 candidates .append (_normalize_sif_id (dockerRequirement ["dockerImageId" ]))
282285 # handling local singularity sandbox image
283- elif os .path .isdir (dockerRequirement ["dockerImageId" ]) and _inspect_singularity_image (dockerRequirement ["dockerImageId" ]):
286+ elif os .path .isdir (dockerRequirement ["dockerImageId" ]) and _inspect_singularity_image (
287+ dockerRequirement ["dockerImageId" ]
288+ ):
284289 _logger .info (
285290 "Using local Singularity sandbox image found in %s" ,
286291 dockerRequirement ["dockerImageId" ],
0 commit comments