Skip to content

Commit d2a4789

Browse files
committed
BUG: use errors=replace for stdout
We print log messages and error messages that may contain file names containing characters that cannot be represented in the stdout encoding. Use replacement markers for those instead than raising UnicodeEncodeError. Fixes #535.
1 parent 2729e79 commit d2a4789

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mesonpy/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ def strip(string: str) -> str:
158158
@functools.lru_cache()
159159
def _use_ansi_colors() -> bool:
160160
"""Determine whether logging should use ANSI color escapes."""
161+
162+
# We print log messages and error messages that may contain file
163+
# names containing characters that cannot be represented in the
164+
# stdout encoding. Use replacement markers for those instead than
165+
# raising UnicodeEncodeError.
166+
sys.stdout.reconfigure(errors='replace') # type: ignore[attr-defined]
167+
161168
if 'NO_COLOR' in os.environ:
162169
return False
163170
if 'FORCE_COLOR' in os.environ or sys.stdout.isatty() and os.environ.get('TERM') != 'dumb':

0 commit comments

Comments
 (0)