Skip to content

Commit

Permalink
Use locale.getpreferredencoding(False) instead of explicit 'utf-8'
Browse files Browse the repository at this point in the history
This fixes Python 3.6 with LC_ALL=C. For Python 3.7+ we always get
'utf-8': https://docs.python.org/3/library/os.html#utf8-mode
  • Loading branch information
bartoldeman committed Mar 14, 2024
1 parent a7b4fb0 commit 38cc5ea
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import contextlib
import functools
import inspect
import locale
import os
import re
import signal
Expand Down Expand Up @@ -350,8 +351,11 @@ def to_cmd_str(cmd):
(stdout, stderr) = proc.communicate(input=stdin)

# return output as a regular string rather than a byte sequence (and non-UTF-8 characters get stripped out)
output = stdout.decode('utf-8', 'ignore')
stderr = stderr.decode('utf-8', 'ignore') if split_stderr else None
# getpreferredencoding normally gives 'utf-8' but can be ASCII (ANSI_X3.4-1968)
# for Python 3.6 and older with LC_ALL=C
encoding = locale.getpreferredencoding(False)
output = stdout.decode(encoding, 'ignore')
stderr = stderr.decode(encoding, 'ignore') if split_stderr else None

# store command output to temporary file(s)
if output_file:
Expand Down

0 comments on commit 38cc5ea

Please sign in to comment.