Skip to content

Commit

Permalink
tests: fix test_vsenv_option with Python 3.11+ on Windows
Browse files Browse the repository at this point in the history
meson tests enable PYTHONWARNDEFAULTENCODING by default and
make EncodingWarning fatal too.

Starting with Python 3.11 CPython not only warns if no encoding is passed
to open() but also to things like subprocess.check_output(). This made
the call in vsenv.py fail and in turn made test_vsenv_option fail.

check_output() here calls a .bat file which in turn calls vcvars. I don't
know what the encoding is supposed to be used there, so just be explicit
with the locale encoding to silence the warning.
  • Loading branch information
lazka authored and nirbheek committed Sep 28, 2023
1 parent fd1f36a commit e77edf4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mesonbuild/utils/vsenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pathlib
import shutil
import tempfile
import locale

from .. import mlog
from .universal import MesonException, is_windows, windows_detect_native_arch
Expand Down Expand Up @@ -92,7 +93,8 @@ def _setup_vsenv(force: bool) -> bool:
bat_file.write(bat_contents)
bat_file.flush()
bat_file.close()
bat_output = subprocess.check_output(bat_file.name, universal_newlines=True)
bat_output = subprocess.check_output(bat_file.name, universal_newlines=True,
encoding=locale.getpreferredencoding(False))
os.unlink(bat_file.name)
bat_lines = bat_output.split('\n')
bat_separator_seen = False
Expand Down

0 comments on commit e77edf4

Please sign in to comment.