8000 Merge pull request #14636 from anntzer/subprocessstderr · matplotlib/matplotlib@8e3b239 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e3b239

Browse files
authored
Merge pull request #14636 from anntzer/subprocessstderr
Don't capture stderr in _check_and_log_subprocess.
2 parents fdcdf4f + 00b06da commit 8e3b239

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,24 +2030,28 @@ def _pformat_subprocess(command):
20302030

20312031
def _check_and_log_subprocess(command, logger, **kwargs):
20322032
"""
2033-
Run *command* using `subprocess.check_output`. If it succeeds, return the
2034-
output (stdout and stderr); if not, raise an exception whose text includes
2035-
the failed command and captured output. Both the command and the output
2036-
are logged at DEBUG level on *logger*.
2033+
Run *command*, returning its stdout output if it succeeds.
2034+
2035+
If it fails (exits with nonzero return code), raise an exception whose text
2036+
includes the failed command and captured stdout and stderr output.
2037+
2038+
Regardless of the return code, the command is logged at DEBUG level on
2039+
*logger*. In case of success, the output is likewise logged.
20372040
"""
20382041
logger.debug('%s', _pformat_subprocess(command))
2039-
try:
2040-
report = subprocess.check_output(
2041-
command, stderr=subprocess.STDOUT, **kwargs)
2042-
except subprocess.CalledProcessError as exc:
2042+
proc = subprocess.run(
2043+
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
2044+
if proc.returncode:
20432045
raise RuntimeError(
2044-
'The command\n'
2045-
' {}\n'
2046-
'failed and generated the following output:\n'
2047-
'{}'
2048-
.format(_pformat_subprocess(command), exc.output.decode('utf-8')))
2049-
logger.debug(report)
2050-
return report
2046+
f"The command\n"
2047+
f" {_pformat_subprocess(command)}\n"
2048+
f"failed and generated the following output:\n"
2049+
f"{proc.stdout.decode('utf-8')}\n"
2050+
f"and the following error:\n"
2051+
f"{proc.stderr.decode('utf-8')}")
2052+
logger.debug("stdout:\n%s", proc.stdout)
2053+
logger.debug("stderr:\n%s", proc.stderr)
2054+
return proc.stdout
20512055

20522056

20532057
def _check_isinstance(types, **kwargs):

0 commit comments

Comments
 (0)
0