diff options
author | Filipe Laíns 🇵🇸 <lains@riseup.net> | 2024-11-17 00:07:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-17 00:07:25 (GMT) |
commit | acbd5c9c6c62dac34d2ed1a789d36fe61841c16d (patch) | |
tree | d7a395437bb356a1f0101ab2ce9f0f8db1e5c091 /Lib/sysconfig | |
parent | ed81971e6b26c34445f06850192b34458b029337 (diff) | |
download | cpython-acbd5c9c6c62dac34d2ed1a789d36fe61841c16d.zip cpython-acbd5c9c6c62dac34d2ed1a789d36fe61841c16d.tar.gz cpython-acbd5c9c6c62dac34d2ed1a789d36fe61841c16d.tar.bz2 |
GH-126789: fix some sysconfig data on late site initializations
Diffstat (limited to 'Lib/sysconfig')
-rw-r--r-- | Lib/sysconfig/__init__.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index 43f9276..ec3b638 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -173,9 +173,7 @@ _SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include', _PY_VERSION = sys.version.split()[0] _PY_VERSION_SHORT = f'{sys.version_info[0]}.{sys.version_info[1]}' _PY_VERSION_SHORT_NO_DOT = f'{sys.version_info[0]}{sys.version_info[1]}' -_PREFIX = os.path.normpath(sys.prefix) _BASE_PREFIX = os.path.normpath(sys.base_prefix) -_EXEC_PREFIX = os.path.normpath(sys.exec_prefix) _BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix) # Mutex guarding initialization of _CONFIG_VARS. _CONFIG_VARS_LOCK = threading.RLock() @@ -466,8 +464,10 @@ def _init_config_vars(): # Normalized versions of prefix and exec_prefix are handy to have; # in fact, these are the standard versions used most places in the # Distutils. - _CONFIG_VARS['prefix'] = _PREFIX - _CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX + _PREFIX = os.path.normpath(sys.prefix) + _EXEC_PREFIX = os.path.normpath(sys.exec_prefix) + _CONFIG_VARS['prefix'] = _PREFIX # FIXME: This gets overwriten by _init_posix. + _CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX # FIXME: This gets overwriten by _init_posix. _CONFIG_VARS['py_version'] = _PY_VERSION _CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT _CONFIG_VARS['py_version_nodot'] = _PY_VERSION_SHORT_NO_DOT @@ -540,6 +540,7 @@ def get_config_vars(*args): With arguments, return a list of values that result from looking up each argument in the configuration variable dictionary. """ + global _CONFIG_VARS_INITIALIZED # Avoid claiming the lock once initialization is complete. if not _CONFIG_VARS_INITIALIZED: @@ -550,6 +551,15 @@ def get_config_vars(*args): # don't re-enter init_config_vars(). if _CONFIG_VARS is None: _init_config_vars() + else: + # If the site module initialization happened after _CONFIG_VARS was + # initialized, a virtual environment might have been activated, resulting in + # variables like sys.prefix changing their value, so we need to re-init the + # config vars (see GH-126789). + if _CONFIG_VARS['base'] != os.path.normpath(sys.prefix): + with _CONFIG_VARS_LOCK: + _CONFIG_VARS_INITIALIZED = False + _init_config_vars() if args: vals = [] |