Skip to content

Commit

Permalink
allow passage of stderr handle in run_and_print
Browse files Browse the repository at this point in the history
allow passage of stderr handle in run_and_print, defaulting to stdout redirection as before if not specified
  • Loading branch information
tomkinsc committed Jul 25, 2018
1 parent 27aff1a commit 4dea8e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/integration/test_intrahost.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TestSnpEff(TestCaseWithTmp):
def capsys(self, capsys):
self.capsys = capsys

@unittest.skipIf(True, "test is marked to be skipped")
#@unittest.skipIf(True, "test is marked to be skipped")
def test_snpeff(self):
temp_dir = tempfile.gettempdir()
input_dir = util.file.get_test_input_path(self)
Expand Down
8 changes: 5 additions & 3 deletions tools/snpeff.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, install_methods=None, extra_genomes=None):
def version(self):
return "4.1"

def execute(self, command, args, JVMmemory=None, stdin=None, stdout=None): # pylint: disable=W0221
def execute(self, command, args, JVMmemory=None, stdin=None, stdout=None, stderr=None): # pylint: disable=W0221
if not JVMmemory:
JVMmemory = self.jvmMemDefault

Expand All @@ -59,7 +59,7 @@ def execute(self, command, args, JVMmemory=None, stdin=None, stdout=None): #
] + args

_log.debug(' '.join(tool_cmd))
return util.misc.run_and_print(tool_cmd, stdin=stdin, buffered=True, silent=("databases" in command), check=True)
return util.misc.run_and_print(tool_cmd, stdin=stdin, stderr=stderr, buffered=True, silent=("databases" in command), check=True)

def has_genome(self, genome):
if not self.known_dbs:
Expand Down Expand Up @@ -109,7 +109,9 @@ def create_db(self, accessions, emailAddress=None, JVMmemory=None):
self.execute('build', args, JVMmemory=JVMmemory)

def available_databases(self):
command_ps = self.execute("databases", args=[])
# do not capture stderr, since snpEff writes 'Picked up _JAVA_OPTIONS'
# which is not helpful for reading the stdout of the databases command
command_ps = self.execute("databases", args=[], stderr=subprocess.DEVNULL)

This comment has been minimized.

Copy link
@notestaff

notestaff Jul 25, 2018

Contributor

@tomkinsc py27 doesn't have subprocess.DEVNULL .


split_points = []
keys = ['Genome', 'Organism', 'Status', 'Bundle', 'Database']
Expand Down
9 changes: 6 additions & 3 deletions util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ def run_and_print(args, stdout=None, stderr=None,
This is useful for nose, which has difficulty capturing stdout of
subprocess invocations.
'''

stderr = stderr or subprocess.STDOUT

This comment has been minimized.

Copy link
@notestaff

notestaff Jul 25, 2018

Contributor

@tomkinsc maybe just put stderr=subprocess.STDOUT in the function declaration, as a default value of the stderr argument?
in theory some of these markers like subprocess.DEVNULL could have a False boolean value, then this still ends up with subprocess.STDOUT


if loglevel:
silent = False
if not buffered:
Expand All @@ -238,7 +241,7 @@ def run_and_print(args, stdout=None, stderr=None,
args,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=stderr,
env=env,
cwd=cwd,
timeout=timeout,
Expand Down Expand Up @@ -268,7 +271,7 @@ def run_and_print(args, stdout=None, stderr=None,
raise(e)
else:
result = run(args, stdin=stdin, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=env, cwd=cwd,
stderr=stderr, env=env, cwd=cwd,
timeout=timeout, check=check)
if not silent and not loglevel:
print(result.stdout.decode('utf-8'))
Expand All @@ -281,7 +284,7 @@ def run_and_print(args, stdout=None, stderr=None,
'CompletedProcess', ['args', 'returncode', 'stdout', 'stderr'])

process = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=env,
stderr=stderr, env=env,
cwd=cwd)
output = []
while process.poll() is None:
Expand Down

0 comments on commit 4dea8e2

Please sign in to comment.