Skip to content

Commit f952b3e

Browse files
committed
abandon subprocess.Run due to Py3.4
1 parent 8e30c7a commit f952b3e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

cwltool/singularity.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@
1313
from .process import (UnsupportedRequirement)
1414
from .utils import docker_windows_path_adjust
1515
if os.name == 'posix' and sys.version_info[0] < 3:
16-
import subprocess32 as subprocess
16+
from subprocess32 import (check_call, check_output, # pylint: disable=import-error
17+
CalledProcessError, DEVNULL, PIPE, Popen,
18+
TimeoutExpired)
1719
else:
18-
import subprocess # type: ignore
20+
from subprocess import (check_call, check_output, # type: ignore
21+
CalledProcessError, DEVNULL, PIPE, Popen,
22+
TimeoutExpired)
1923

2024
_logger = logging.getLogger("cwltool")
2125
_USERNS = None
2226

2327
def _singularity_supports_userns(): # type: ()->bool
2428
global _USERNS # pylint: disable=global-statement
2529
if _USERNS is None:
26-
_USERNS = "No valid /bin/sh" in subprocess.run(
27-
[u"singularity", u"exec", u"--userns", u"/etc", u"true"],
28-
stderr=subprocess.PIPE).stderr.decode('utf-8')
30+
try:
31+
_USERNS = "No valid /bin/sh" in Popen(
32+
[u"singularity", u"exec", u"--userns", u"/etc", u"true"],
33+
stderr=PIPE, stdout=DEVNULL).communicate(timeout=60)[1]
34+
except TimeoutExpired:
35+
_USERNS = False
2936
return _USERNS
3037

3138

@@ -92,7 +99,7 @@ def get_image(dockerRequirement, # type: Dict[Text, Text]
9299
str(dockerRequirement["dockerPull"])]
93100
_logger.info(Text(cmd))
94101
if not dry_run:
95-
subprocess.check_call(cmd, stdout=sys.stderr)
102+
check_call(cmd, stdout=sys.stderr)
96103
found = True
97104

98105
return found
@@ -117,8 +124,8 @@ def get_from_requirements(self,
117124
if r:
118125
errmsg = None
119126
try:
120-
subprocess.check_output(["singularity", "--version"])
121-
except subprocess.CalledProcessError as err:
127+
check_output(["singularity", "--version"])
128+
except CalledProcessError as err:
122129
errmsg = "Cannot execute 'singularity --version' {}".format(err)
123130
except OSError as err:
124131
errmsg = "'singularity' executable not found: {}".format(err)

typeshed/2and3/subprocess32.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def check_output(args: _CMD,
123123

124124
PIPE = ... # type: int
125125
STDOUT = ... # type: int
126+
DEVNULL = ... # type: int
126127
class SubprocessError(Exception): ...
127128
class TimeoutExpired(SubprocessError):
128129
# morally: _CMD

0 commit comments

Comments
 (0)