Skip to content

Commit 428c25f

Browse files
lint: fix linting with cleanup
1 parent 2011c9e commit 428c25f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cwltool/singularity.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import os.path
77
import re
88
import shutil
9-
import subprocess
109
import sys
1110
from collections.abc import MutableMapping
12-
from subprocess import DEVNULL, check_call, check_output, run # nosec
11+
from subprocess import check_call, check_output, run # nosec
1312
from typing import Callable, Optional, cast
1413

1514
from 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+
149149
def _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+
171172
class 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"],

tests/test_singularity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ def test_singularity3_docker_image_id_in_tool(tmp_path: Path) -> None:
160160
)
161161
assert result_code1 == 0
162162

163+
163164
@needs_singularity
164165
def test_singularity_local_sandbox_image(tmp_path: Path):
165166
import subprocess
167+
166168
workdir = tmp_path / "working_dir"
167169
workdir.mkdir()
168170
with working_directory(workdir):
@@ -174,7 +176,7 @@ def test_singularity_local_sandbox_image(tmp_path: Path):
174176
"build",
175177
"--sandbox",
176178
container_path / "alpine",
177-
"docker://alpine:latest"
179+
"docker://alpine:latest",
178180
]
179181
build = subprocess.run(cmd, capture_output=True, text=True)
180182
if build.returncode == 0:

0 commit comments

Comments
 (0)