Skip to content

Commit 9cc5c44

Browse files
committed
Revert "pythonGH-126789: fix some sysconfig data on late site initializations"
This reverts commit acbd5c9. Signed-off-by: Filipe Laíns <[email protected]>
1 parent 1380972 commit 9cc5c44

File tree

4 files changed

+5
-154
lines changed

4 files changed

+5
-154
lines changed

Lib/sysconfig/__init__.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def joinuser(*args):
173173
_PY_VERSION = sys.version.split()[0]
174174
_PY_VERSION_SHORT = f'{sys.version_info[0]}.{sys.version_info[1]}'
175175
_PY_VERSION_SHORT_NO_DOT = f'{sys.version_info[0]}{sys.version_info[1]}'
176+
_PREFIX = os.path.normpath(sys.prefix)
176177
_BASE_PREFIX = os.path.normpath(sys.base_prefix)
178+
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
177179
_BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
178180
# Mutex guarding initialization of _CONFIG_VARS.
179181
_CONFIG_VARS_LOCK = threading.RLock()
@@ -465,10 +467,8 @@ def _init_config_vars():
465467
# Normalized versions of prefix and exec_prefix are handy to have;
466468
# in fact, these are the standard versions used most places in the
467469
# Distutils.
468-
_PREFIX = os.path.normpath(sys.prefix)
469-
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
470-
_CONFIG_VARS['prefix'] = _PREFIX # FIXME: This gets overwriten by _init_posix.
471-
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX # FIXME: This gets overwriten by _init_posix.
470+
_CONFIG_VARS['prefix'] = _PREFIX
471+
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
472472
_CONFIG_VARS['py_version'] = _PY_VERSION
473473
_CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
474474
_CONFIG_VARS['py_version_nodot'] = _PY_VERSION_SHORT_NO_DOT
@@ -541,7 +541,6 @@ def get_config_vars(*args):
541541
With arguments, return a list of values that result from looking up
542542
each argument in the configuration variable dictionary.
543543
"""
544-
global _CONFIG_VARS_INITIALIZED
545544

546545
# Avoid claiming the lock once initialization is complete.
547546
if not _CONFIG_VARS_INITIALIZED:
@@ -552,15 +551,6 @@ def get_config_vars(*args):
552551
# don't re-enter init_config_vars().
553552
if _CONFIG_VARS is None:
554553
_init_config_vars()
555-
else:
556-
# If the site module initialization happened after _CONFIG_VARS was
557-
# initialized, a virtual environment might have been activated, resulting in
558-
# variables like sys.prefix changing their value, so we need to re-init the
559-
# config vars (see GH-126789).
560-
if _CONFIG_VARS['base'] != os.path.normpath(sys.prefix):
561-
with _CONFIG_VARS_LOCK:
562-
_CONFIG_VARS_INITIALIZED = False
563-
_init_config_vars()
564554

565555
if args:
566556
vals = []

Lib/test/support/venv.py

-70
This file was deleted.

Lib/test/test_sysconfig.py

+1-66
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def venv(self, **venv_create_args):
110110
**venv_create_args,
111111
)
112112

113+
113114
def test_get_path_names(self):
114115
self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)
115116

@@ -591,71 +592,6 @@ def test_osx_ext_suffix(self):
591592
suffix = sysconfig.get_config_var('EXT_SUFFIX')
592593
self.assertTrue(suffix.endswith('-darwin.so'), suffix)
593594

594-
@requires_subprocess()
595-
def test_config_vars_depend_on_site_initialization(self):
596-
script = textwrap.dedent("""
597-
import sysconfig
598-
599-
config_vars = sysconfig.get_config_vars()
600-
601-
import json
602-
print(json.dumps(config_vars, indent=2))
603-
""")
604-
605-
with self.venv() as venv:
606-
site_config_vars = json.loads(venv.run('-c', script).stdout)
607-
no_site_config_vars = json.loads(venv.run('-S', '-c', script).stdout)
608-
609-
self.assertNotEqual(site_config_vars, no_site_config_vars)
610-
# With the site initialization, the virtual environment should be enabled.
611-
self.assertEqual(site_config_vars['base'], venv.prefix)
612-
self.assertEqual(site_config_vars['platbase'], venv.prefix)
613-
#self.assertEqual(site_config_vars['prefix'], venv.prefix) # # FIXME: prefix gets overwriten by _init_posix
614-
# Without the site initialization, the virtual environment should be disabled.
615-
self.assertEqual(no_site_config_vars['base'], site_config_vars['installed_base'])
616-
self.assertEqual(no_site_config_vars['platbase'], site_config_vars['installed_platbase'])
617-
618-
@requires_subprocess()
619-
def test_config_vars_recalculation_after_site_initialization(self):
620-
script = textwrap.dedent("""
621-
import sysconfig
622-
623-
before = sysconfig.get_config_vars()
624-
625-
import site
626-
site.main()
627-
628-
after = sysconfig.get_config_vars()
629-
630-
import json
631-
print(json.dumps({'before': before, 'after': after}, indent=2))
632-
""")
633-
634-
with self.venv() as venv:
635-
config_vars = json.loads(venv.run('-S', '-c', script).stdout)
636-
637-
self.assertNotEqual(config_vars['before'], config_vars['after'])
638-
self.assertEqual(config_vars['after']['base'], venv.prefix)
639-
#self.assertEqual(config_vars['after']['prefix'], venv.prefix) # FIXME: prefix gets overwriten by _init_posix
640-
#self.assertEqual(config_vars['after']['exec_prefix'], venv.prefix) # FIXME: exec_prefix gets overwriten by _init_posix
641-
642-
@requires_subprocess()
643-
def test_paths_depend_on_site_initialization(self):
644-
script = textwrap.dedent("""
645-
import sysconfig
646-
647-
paths = sysconfig.get_paths()
648-
649-
import json
650-
print(json.dumps(paths, indent=2))
651-
""")
652-
653-
with self.venv() as venv:
654-
site_paths = json.loads(venv.run('-c', script).stdout)
655-
no_site_paths = json.loads(venv.run('-S', '-c', script).stdout)
656-
657-
self.assertNotEqual(site_paths, no_site_paths)
658-
659595
@requires_subprocess()
660596
def test_makefile_overwrites_config_vars(self):
661597
script = textwrap.dedent("""
@@ -689,7 +625,6 @@ def test_makefile_overwrites_config_vars(self):
689625
self.assertNotEqual(data['prefix'], data['base_prefix'])
690626
self.assertNotEqual(data['exec_prefix'], data['base_exec_prefix'])
691627

692-
693628
class MakefileTests(unittest.TestCase):
694629

695630
@unittest.skipIf(sys.platform.startswith('win'),

Misc/NEWS.d/next/Library/2024-11-13-22-25-57.gh-issue-126789.lKzlc7.rst

-4
This file was deleted.

0 commit comments

Comments
 (0)