Skip to content

Commit 06356b0

Browse files
committed
pythonGH-126789: fix some sysconfig data on late site initializations
Signed-off-by: Filipe Laíns <[email protected]>
1 parent 12ca7e6 commit 06356b0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Lib/sysconfig/__init__.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ 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)
177176
_BASE_PREFIX = os.path.normpath(sys.base_prefix)
178-
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
179177
_BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
180178
# Mutex guarding initialization of _CONFIG_VARS.
181179
_CONFIG_VARS_LOCK = threading.RLock()
@@ -466,8 +464,10 @@ def _init_config_vars():
466464
# Normalized versions of prefix and exec_prefix are handy to have;
467465
# in fact, these are the standard versions used most places in the
468466
# Distutils.
469-
_CONFIG_VARS['prefix'] = _PREFIX
470-
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
467+
_PREFIX = os.path.normpath(sys.prefix)
468+
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
469+
_CONFIG_VARS['prefix'] = _PREFIX # FIXME: This gets overwriten by _init_posix.
470+
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX # FIXME: This gets overwriten by _init_posix.
471471
_CONFIG_VARS['py_version'] = _PY_VERSION
472472
_CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
473473
_CONFIG_VARS['py_version_nodot'] = _PY_VERSION_SHORT_NO_DOT
@@ -540,6 +540,7 @@ def get_config_vars(*args):
540540
With arguments, return a list of values that result from looking up
541541
each argument in the configuration variable dictionary.
542542
"""
543+
global _CONFIG_VARS_INITIALIZED
543544

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

554564
if args:
555565
vals = []

0 commit comments

Comments
 (0)