Skip to content

Commit 5337461

Browse files
[3.14] gh-154592: Fix test_peg_generator in non-UTF-8 locales with a non-ASCII work dir (GH-154593) (GH-154602)
(cherry picked from commit da46947) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ac0b2b8 commit 5337461

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/test/test_peg_generator/test_c_parser.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ def setUpClass(cls):
100100

101101
with contextlib.ExitStack() as stack:
102102
python_exe = stack.enter_context(support.setup_venv_with_pip_setuptools("venv"))
103-
sitepackages = subprocess.check_output(
104-
[python_exe, "-c", "import sysconfig; print(sysconfig.get_path('platlib'))"],
105-
text=True,
106-
).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+
sitepackages = get_sysconfig_path("platlib")
107113
stack.enter_context(import_helper.DirsOnSysPath(sitepackages))
108114
cls.addClassCleanup(stack.pop_all().close)
109115

0 commit comments

Comments
 (0)