File tree Expand file tree Collapse file tree 4 files changed +65
-6
lines changed
planemo_ext/galaxy/tools/deps Expand file tree Collapse file tree 4 files changed +65
-6
lines changed Original file line number Diff line number Diff line change 44from tempfile import mkstemp
55
66from planemo .cli import pass_context
7- from galaxy . tools . deps import commands
7+ from planemo . io import shell
88
99
1010INSTALL_SCRIPT = "https://raw.github.com/Homebrew/linuxbrew/go/install"
@@ -24,4 +24,4 @@ def cli(ctx):
2424 """
2525 fname = mkstemp ('install_brew' )
2626 urllib .urlretrieve (INSTALL_SCRIPT , fname )
27- commands . execute (["ruby" , fname ])
27+ shell (["ruby" , fname ])
Original file line number Diff line number Diff line change 1818def communicate (cmds , ** kwds ):
1919 info (cmds )
2020 p = commands .shell_process (cmds , ** kwds )
21- ret_val = p .communicate ()
21+ if kwds .get ("stdout" , None ) is None and commands .redirecting_io (sys = sys ):
22+ output = commands .redirect_aware_commmunicate (p )
23+ else :
24+ output = p .communicate ()
25+
2226 if p .returncode != 0 :
2327 template = "Problem executing commands {0} - ({1}, {2})"
24- msg = template .format (cmds , ret_val [0 ], ret_val [1 ])
28+ msg = template .format (cmds , output [0 ], output [1 ])
2529 raise RuntimeError (msg )
26- return ret_val
30+ return output
2731
2832
2933def shell (cmds , ** kwds ):
Original file line number Diff line number Diff line change 11import os
22import subprocess
3+ import sys as _sys
4+
5+
6+ def redirecting_io (sys = _sys ):
7+ assert sys is not None
8+ # We are redirecting standard out and standard error.
9+ return not hasattr (sys .stdout , "fileno" )
10+
11+
12+ def redirect_aware_commmunicate (p , sys = _sys ):
13+ assert sys is not None
14+ out , err = p .communicate ()
15+ if redirecting_io (sys = sys ):
16+ if out :
17+ sys .stdout .write (out )
18+ out = None
19+ if err :
20+ sys .stderr .write (err )
21+ err = None
22+ return out , err
323
424
525def shell (cmds , env = None , ** kwds ):
26+ sys = kwds .get ("sys" , _sys )
27+ assert sys is not None
628 p = shell_process (cmds , env , ** kwds )
7- return p .wait ()
29+ if redirecting_io (sys = sys ):
30+ redirect_aware_commmunicate (p , sys = sys )
31+ exit = p .returncode
32+ return exit
33+ else :
34+ return p .wait ()
835
936
1037def shell_process (cmds , env = None , ** kwds ):
38+ sys = kwds .get ("sys" , _sys )
1139 popen_kwds = dict (
1240 shell = True ,
1341 )
42+ if kwds .get ("stdout" , None ) is None and redirecting_io (sys = sys ):
43+ popen_kwds ["stdout" ] = subprocess .PIPE
44+ if kwds .get ("stderr" , None ) is None and redirecting_io (sys = sys ):
45+ popen_kwds ["stderr" ] = subprocess .PIPE
46+
1447 popen_kwds .update (** kwds )
1548 if env :
1649 new_env = os .environ .copy ()
Original file line number Diff line number Diff line change 1+ from .test_utils import io
2+
3+
4+ def test_io_capture ():
5+ with io .conditionally_captured_io (True , tee = False ) as capture :
6+ io .warn ("Problem..." )
7+ assert capture [0 ]["data" ] == "Problem..."
8+
9+ with io .conditionally_captured_io (True , tee = False ) as capture :
10+ io .shell ("echo 'Problem...'" )
11+ assert capture [0 ]["data" ] == "echo 'Problem...'"
12+ assert capture [1 ]["data" ] == "Problem..."
13+
14+ with io .conditionally_captured_io (True , tee = False ) as capture :
15+ io .communicate ("echo 'Problem...'" )
16+ assert capture [0 ]["data" ] == "echo 'Problem...'"
17+ assert capture [1 ]["data" ] == "Problem..."
18+
19+ with io .conditionally_captured_io (False , tee = False ) as capture :
20+ io .communicate ("echo 'Test...'" )
21+
22+ assert capture is None
You can’t perform that action at this time.
0 commit comments