8000 Don't capture stderr in _check_and_log_subprocess. by anntzer · Pull Request #14636 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Don't capture stderr in _check_and_log_subprocess. #14636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2030,24 +2030,28 @@ def _pformat_subprocess(command):

def _check_and_log_subprocess(command, logger, **kwargs):
"""
Run *command* using `subprocess.check_output`. If it succeeds, return the
output (stdout and stderr); if not, raise an exception whose text includes
the failed command and captured output. Both the command and the output
are logged at DEBUG level on *logger*.
Run *command*, returning its stdout output if it succeeds.

If it fails (exits with nonzero return code), raise an exception whose text
includes the failed command and captured stdout and stderr output.

Regardless of the return code, the command is logged at DEBUG level on
*logger*. In case of success, the output is likewise logged.
"""
logger.debug('%s', _pformat_subprocess(command))
try:
report = subprocess.check_output(
command, stderr=subprocess.STDOUT, **kwargs)
except subprocess.CalledProcessError as exc:
proc = subprocess.run(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
if proc.returncode:
raise RuntimeError(
'The command\n'
' {}\n'
'failed and generated the following output:\n'
'{}'
.format(_pformat_subprocess(command), exc.output.decode('utf-8')))
logger.debug(report)
return report
f"The command\n"
f" {_pformat_subprocess(command)}\n"
f"failed and generated the following output:\n"
f"{proc.stdout.decode('utf-8')}\n"
f"and the following error:\n"
f"{proc.stderr.decode('utf-8')}")
logger.debug("stdout:\n%s", proc.stdout)
logger.debug("stderr:\n%s", proc.stderr)
return proc.stdout


def _check_isinstance(types, **kwargs):
Expand Down
0