Skip to content

Commit dae34cd

Browse files
committed
gh-128690: Update test_embed for getpath.py exec_prefix change
1 parent 13475e0 commit dae34cd

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Lib/test/test_embed.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
MAX_HASH_SEED = 4294967295
5252

5353
ABI_THREAD = 't' if sysconfig.get_config_var('Py_GIL_DISABLED') else ''
54+
# PLATSTDLIB_LANDMARK copied from Modules/getpath.py
55+
if os.name == 'nt':
56+
PLATSTDLIB_LANDMARK = f'{sys.platlibdir}'
57+
else:
58+
VERSION_MAJOR = sys.version_info.major
59+
VERSION_MINOR = sys.version_info.minor
60+
PLATSTDLIB_LANDMARK = (f'{sys.platlibdir}/python{VERSION_MAJOR}.'
61+
f'{VERSION_MINOR}{ABI_THREAD}/lib-dynload')
5462

5563

5664
# If we are running from a build dir, but the stdlib has been installed,
@@ -1596,7 +1604,13 @@ def test_init_pyvenv_cfg(self):
15961604

15971605
with self.tmpdir_with_python() as tmpdir, \
15981606
tempfile.TemporaryDirectory() as pyvenv_home:
1607+
15991608
ver = sys.version_info
1609+
base_prefix = sysconfig.get_config_var("prefix")
1610+
1611+
# gh-128690: base_exec_prefix depends if PLATSTDLIB_LANDMARK exists
1612+
platstdlib = os.path.join(base_prefix, PLATSTDLIB_LANDMARK)
1613+
change_exec_prefix = not os.path.isdir(platstdlib)
16001614

16011615
if not MS_WINDOWS:
16021616
lib_dynload = os.path.join(pyvenv_home,
@@ -1620,7 +1634,8 @@ def test_init_pyvenv_cfg(self):
16201634

16211635
paths = self.module_search_paths()
16221636
if not MS_WINDOWS:
1623-
paths[-1] = lib_dynload
1637+
if change_exec_prefix:
1638+
paths[-1] = lib_dynload
16241639
else:
16251640
paths = [
16261641
os.path.join(tmpdir, os.path.basename(paths[0])),
@@ -1630,16 +1645,16 @@ def test_init_pyvenv_cfg(self):
16301645

16311646
executable = self.test_exe
16321647
base_executable = os.path.join(pyvenv_home, os.path.basename(executable))
1633-
exec_prefix = pyvenv_home
16341648
config = {
1635-
'base_prefix': sysconfig.get_config_var("prefix"),
1636-
'base_exec_prefix': exec_prefix,
1649+
'base_prefix': base_prefix,
16371650
'exec_prefix': tmpdir,
16381651
'prefix': tmpdir,
16391652
'base_executable': base_executable,
16401653
'executable': executable,
16411654
'module_search_paths': paths,
16421655
}
1656+
if change_exec_prefix:
1657+
config['base_exec_prefix'] = pyvenv_home
16431658
if MS_WINDOWS:
16441659
config['base_prefix'] = pyvenv_home
16451660
config['stdlib_dir'] = os.path.join(pyvenv_home, 'Lib')

0 commit comments

Comments
 (0)