Skip to content
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

Fix encoding used to read our own log files #2390

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 12 additions & 1 deletion src/tox/action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals

import locale
import os
import pipes
import signal
Expand Down Expand Up @@ -125,7 +126,17 @@ def popen(
exit_code = process.returncode
finally:
if out_path is not None and out_path.exists():
lines = out_path.read_text("UTF-8").split("\n")
# Output of Python sub-processes like `python -m
# virtualenv` may use some other system-dependent
# encoding when redirected to a file. Let's try
# UTF-8 (the common case) and fall back to the
# system encoding if that fails.
try:
encoding = "UTF-8"
lines = out_path.read_text(encoding).split("\n")
except UnicodeDecodeError:
encoding = locale.getpreferredencoding(False)
lines = out_path.read_text(encoding).split("\n")
# first three lines are the action, cwd, and cmd - remove it
output = "\n".join(lines[3:])
try:
Expand Down