Skip to content

Commit da46947

Browse files
gh-154592: Fix test_peg_generator in non-UTF-8 locales with a non-ASCII work dir (GH-154593)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ae72d0c commit da46947

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Lib/test/test_peg_generator/test_c_parser.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,17 @@ def setUpClass(cls):
100100

101101
with contextlib.ExitStack() as stack:
102102
python_exe = stack.enter_context(support.setup_venv_with_pip_setuptools("venv"))
103-
platlib_path = subprocess.check_output(
104-
[python_exe, "-c", "import sysconfig; print(sysconfig.get_path('platlib'))"],
105-
text=True,
106-
).strip()
107-
purelib_path = subprocess.check_output(
108-
[python_exe, "-c", "import sysconfig; print(sysconfig.get_path('purelib'))"],
109-
text=True,
110-
).strip()
103+
104+
def get_sysconfig_path(name):
105+
# Force UTF-8 to emit the non-ASCII venv path in any locale.
106+
return subprocess.check_output(
107+
[python_exe, "-X", "utf8", "-c",
108+
f"import sysconfig; print(sysconfig.get_path({name!r}))"],
109+
encoding="utf-8",
110+
).strip()
111+
112+
platlib_path = get_sysconfig_path("platlib")
113+
purelib_path = get_sysconfig_path("purelib")
111114
stack.enter_context(import_helper.DirsOnSysPath(platlib_path, purelib_path))
112115
cls.addClassCleanup(stack.pop_all().close)
113116

0 commit comments

Comments
 (0)