[Fix] Get correct encoding in Windows for collect_env() (#1887)

* [Fix] get correct encoding in Windows for collect_env()

* stdout.fileno()
This commit is contained in:
Tan SU 2022-04-18 17:27:22 +08:00 committed by GitHub
parent b80447707c
commit a5cfcb93ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,13 +81,13 @@ def collect_env():
# on Windows, cl.exe is not in PATH. We need to find the path.
# distutils.ccompiler.new_compiler() returns a msvccompiler
# object and after initialization, path to cl.exe is found.
import locale
import os
from distutils.ccompiler import new_compiler
ccompiler = new_compiler()
ccompiler.initialize()
cc = subprocess.check_output(
f'{ccompiler.cc}', stderr=subprocess.STDOUT, shell=True)
encoding = locale.getdefaultlocale()[1]
encoding = os.device_encoding(sys.stdout.fileno()) or 'utf-8'
env_info['MSVC'] = cc.decode(encoding).partition('\n')[0].strip()
env_info['GCC'] = 'n/a'
except subprocess.CalledProcessError: