Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9d6366b

Browse filesBrowse files
authored
GH-126920: fix Makefile overwriting sysconfig.get_config_vars
1 parent acbd5c9 commit 9d6366b
Copy full SHA for 9d6366b

File tree

Expand file treeCollapse file tree

3 files changed

+39
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+39
-1
lines changed

‎Lib/sysconfig/__init__.py

Copy file name to clipboardExpand all lines: Lib/sysconfig/__init__.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ def _init_posix(vars):
353353
else:
354354
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
355355
build_time_vars = _temp.build_time_vars
356-
vars.update(build_time_vars)
356+
# GH-126920: Make sure we don't overwrite any of the keys already set
357+
vars.update(build_time_vars | vars)
357358

358359
def _init_non_posix(vars):
359360
"""Initialize the module as appropriate for NT"""

‎Lib/test/test_sysconfig.py

Copy file name to clipboardExpand all lines: Lib/test/test_sysconfig.py
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,38 @@ def test_paths_depend_on_site_initialization(self):
656656

657657
self.assertNotEqual(site_paths, no_site_paths)
658658

659+
@unittest.skipIf(sys.platform == 'wasi', 'venv is unsupported on WASI')
660+
def test_makefile_overwrites_config_vars(self):
661+
script = textwrap.dedent("""
662+
import sys, sysconfig
663+
664+
data = {
665+
'prefix': sys.prefix,
666+
'exec_prefix': sys.exec_prefix,
667+
'base_prefix': sys.base_prefix,
668+
'base_exec_prefix': sys.base_exec_prefix,
669+
'config_vars': sysconfig.get_config_vars(),
670+
}
671+
672+
import json
673+
print(json.dumps(data, indent=2))
674+
""")
675+
676+
# We need to run the test inside a virtual environment so that
677+
# sys.prefix/sys.exec_prefix have a different value from the
678+
# prefix/exec_prefix Makefile variables.
679+
with self.venv() as venv:
680+
data = json.loads(venv.run('-c', script).stdout)
681+
682+
# We expect sysconfig.get_config_vars to correctly reflect sys.prefix/sys.exec_prefix
683+
self.assertEqual(data['prefix'], data['config_vars']['prefix'])
684+
self.assertEqual(data['exec_prefix'], data['config_vars']['exec_prefix'])
685+
# As a sanity check, just make sure sys.prefix/sys.exec_prefix really
686+
# are different from the Makefile values.
687+
# sys.base_prefix/sys.base_exec_prefix should reflect the value of the
688+
# prefix/exec_prefix Makefile variables, so we use them in the comparison.
689+
self.assertNotEqual(data['prefix'], data['base_prefix'])
690+
self.assertNotEqual(data['exec_prefix'], data['base_exec_prefix'])
659691

660692
class MakefileTests(unittest.TestCase):
661693

+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix the ``prefix`` and ``exec_prefix`` keys from
2+
:py:func:`sysconfig.get_config_vars` incorrectly having the same value as
3+
:py:const:`sys.base_prefix` and :py:const:`sys.base_exec_prefix`,
4+
respectively, inside virtual environments. They now accurately reflect
5+
:py:const:`sys.prefix` and :py:const:`sys.exec_prefix`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.