Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit 9f3e744

Browse files
authored
Merge pull request #89 from nsoranzo/fixes_for_py3_planemo
Fixes for Python3 planemo
2 parents 0c69916 + fcfb1ae commit 9f3e744

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

galaxy/tools/deps/commands.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@
33
import subprocess
44
import sys as _sys
55

6+
import six
67
from six.moves import shlex_quote
78

8-
from galaxy.util import which
9+
from galaxy.util import (
10+
unicodify,
11+
which
12+
)
913

1014
STDOUT_INDICATOR = "-"
1115

1216

1317
def redirecting_io(sys=_sys):
14-
"""Predicate to determine if we are redicting I/O in process."""
18+
"""Predicate to determine if we are redicting stdout in process."""
1519
assert sys is not None
16-
return not hasattr(sys.stdout, "fileno")
20+
try:
21+
# Need to explicitly call fileno() because sys.stdout could be a
22+
# io.StringIO object, which has a fileno() method but only raises an
23+
# io.UnsupportedOperation exception
24+
sys.stdout.fileno()
25+
except Exception:
26+
return True
27+
else:
28+
return False
1729

1830

1931
def redirect_aware_commmunicate(p, sys=_sys):
@@ -22,9 +34,15 @@ def redirect_aware_commmunicate(p, sys=_sys):
2234
out, err = p.communicate()
2335
if redirecting_io(sys=sys):
2436
if out:
37+
# We don't unicodify in Python2 because sys.stdout may be a
38+
# cStringIO.StringIO object, which does not accept Unicode strings
39+
if not six.PY2:
40+
out = unicodify(out)
2541
sys.stdout.write(out)
2642
out = None
2743
if err:
44+
if not six.PY2:
45+
err = unicodify(err)
2846
sys.stderr.write(err)
2947
err = None
3048
return out, err

0 commit comments

Comments
 (0)