Skip to content

Commit 14c3f8f

Browse files
Replace distutils.spawn usage (#1426)
1 parent 3758687 commit 14c3f8f

File tree

6 files changed

+16
-19
lines changed

6 files changed

+16
-19
lines changed

cwltool/docker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import subprocess # nosec
99
import sys
1010
import threading
11-
from distutils import spawn
1211
from io import StringIO # pylint: disable=redefined-builtin
1312
from typing import Callable, Dict, List, MutableMapping, Optional, Set, Tuple, cast
1413

@@ -235,7 +234,7 @@ def get_from_requirements(
235234
force_pull: bool,
236235
tmp_outdir_prefix: str,
237236
) -> Optional[str]:
238-
if not spawn.find_executable("docker"):
237+
if not shutil.which("docker"):
239238
raise WorkflowException("docker executable is not available")
240239

241240
if self.get_image(

cwltool/singularity.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import re
66
import shutil
77
import sys
8-
from distutils import spawn
98
from subprocess import ( # nosec
109
DEVNULL,
1110
PIPE,
@@ -267,7 +266,7 @@ def get_from_requirements(
267266
268267
(e.g. hello-world-latest.{img,sif}).
269268
"""
270-
if not bool(spawn.find_executable("singularity")):
269+
if not bool(shutil.which("singularity")):
271270
raise WorkflowException("singularity executable is not available")
272271

273272
if not self.get_image(cast(Dict[str, str], r), pull_image, force_pull):

tests/test_dependencies.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from distutils import spawn
2+
from shutil import which
33

44
import pytest
55

@@ -35,9 +35,7 @@ def test_bioconda() -> None:
3535
assert error_code == 0, stderr
3636

3737

38-
@pytest.mark.skipif(
39-
not spawn.find_executable("modulecmd"), reason="modulecmd not installed"
40-
)
38+
@pytest.mark.skipif(not which("modulecmd"), reason="modulecmd not installed")
4139
def test_modules() -> None:
4240
wflow = get_data("tests/random_lines.cwl")
4341
job = get_data("tests/random_lines_job.json")

tests/test_docker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from distutils import spawn
1+
"""Tests for docker engine."""
2+
from shutil import which
23
from pathlib import Path
34

45
from cwltool.main import main
@@ -35,7 +36,7 @@ def test_docker_iwdr() -> None:
3536
"hello",
3637
]
3738
)
38-
docker_installed = bool(spawn.find_executable("docker"))
39+
docker_installed = bool(which("docker"))
3940
if docker_installed:
4041
assert result_code == 0
4142
else:

tests/test_singularity.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import distutils.spawn
1+
"""Tests to find local Singularity image."""
2+
import shutil
23
import os
34
import sys
45
from pathlib import Path
@@ -70,7 +71,7 @@ def test_singularity_iwdr() -> None:
7071
"hello",
7172
]
7273
)
73-
singularity_installed = bool(distutils.spawn.find_executable("singularity"))
74+
singularity_installed = bool(shutil.which("singularity"))
7475
if singularity_installed:
7576
assert result_code == 0
7677
else:

tests/util.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import contextlib
2-
import distutils.spawn # pylint: disable=no-name-in-module,import-error
2+
import shutil # pylint: disable=no-name-in-module,import-error
33
import functools
44
import io
55
import os
@@ -53,29 +53,28 @@ def get_data(filename: str) -> str:
5353

5454

5555
needs_docker = pytest.mark.skipif(
56-
not bool(distutils.spawn.find_executable("docker")),
56+
not bool(shutil.which("docker")),
5757
reason="Requires the docker executable on the system path.",
5858
)
5959

6060
needs_singularity = pytest.mark.skipif(
61-
not bool(distutils.spawn.find_executable("singularity")),
61+
not bool(shutil.which("singularity")),
6262
reason="Requires the singularity executable on the system path.",
6363
)
6464

6565
needs_singularity_2_6 = pytest.mark.skipif(
66-
not bool(distutils.spawn.find_executable("singularity") and is_version_2_6()),
66+
not bool(shutil.which("singularity") and is_version_2_6()),
6767
reason="Requires that version 2.6.x of singularity executable version is on the system path.",
6868
)
6969

7070
needs_singularity_3_or_newer = pytest.mark.skipif(
71-
(not bool(distutils.spawn.find_executable("singularity")))
72-
or (not is_version_3_or_newer()),
71+
(not bool(shutil.which("singularity"))) or (not is_version_3_or_newer()),
7372
reason="Requires that version 3.x of singularity executable version is on the system path.",
7473
)
7574

7675

7776
windows_needs_docker = pytest.mark.skipif(
78-
onWindows() and not bool(distutils.spawn.find_executable("docker")),
77+
onWindows() and not bool(shutil.which("docker")),
7978
reason="Running this test on MS Windows requires the docker executable "
8079
"on the system path.",
8180
)

0 commit comments

Comments
 (0)