From fed39249c351f2614adbec9b65a9a1515f481c0f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 24 Jul 2026 14:34:29 +0300 Subject: [PATCH] gh-154592: Fix test_peg_generator in non-UTF-8 locales with a non-ASCII work dir setUpClass created a venv in the regrtest working directory (whose name has a non-ASCII suffix) and ran a child printing sysconfig.get_path(). In a locale whose encoding cannot encode that character, the child failed to encode the path. Force UTF-8 for the child. Co-Authored-By: Claude Opus 4.8 --- Lib/test/test_peg_generator/test_c_parser.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_peg_generator/test_c_parser.py b/Lib/test/test_peg_generator/test_c_parser.py index 3500f229b1b3863..dc887693840a007 100644 --- a/Lib/test/test_peg_generator/test_c_parser.py +++ b/Lib/test/test_peg_generator/test_c_parser.py @@ -100,14 +100,17 @@ def setUpClass(cls): with contextlib.ExitStack() as stack: python_exe = stack.enter_context(support.setup_venv_with_pip_setuptools("venv")) - platlib_path = subprocess.check_output( - [python_exe, "-c", "import sysconfig; print(sysconfig.get_path('platlib'))"], - text=True, - ).strip() - purelib_path = subprocess.check_output( - [python_exe, "-c", "import sysconfig; print(sysconfig.get_path('purelib'))"], - text=True, - ).strip() + + def get_sysconfig_path(name): + # Force UTF-8 to emit the non-ASCII venv path in any locale. + return subprocess.check_output( + [python_exe, "-X", "utf8", "-c", + f"import sysconfig; print(sysconfig.get_path({name!r}))"], + encoding="utf-8", + ).strip() + + platlib_path = get_sysconfig_path("platlib") + purelib_path = get_sysconfig_path("purelib") stack.enter_context(import_helper.DirsOnSysPath(platlib_path, purelib_path)) cls.addClassCleanup(stack.pop_all().close)