@@ -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 ()
@@ -316,22 +318,14 @@ def get_default_scheme():
316318
317319def get_makefile_filename ():
318320 """Return the path of the Makefile."""
319-
320- # GH-127429: When cross-compiling, use the Makefile from the target, instead of the host Python.
321- if cross_base := os .environ .get ('_PYTHON_PROJECT_BASE' ):
322- return os .path .join (cross_base , 'Makefile' )
323-
324321 if _PYTHON_BUILD :
325322 return os .path .join (_PROJECT_BASE , "Makefile" )
326-
327323 if hasattr (sys , 'abiflags' ):
328324 config_dir_name = f'config-{ _PY_VERSION_SHORT } { sys .abiflags } '
329325 else :
330326 config_dir_name = 'config'
331-
332327 if hasattr (sys .implementation , '_multiarch' ):
333328 config_dir_name += f'-{ sys .implementation ._multiarch } '
334-
335329 return os .path .join (get_path ('stdlib' ), config_dir_name , 'Makefile' )
336330
337331
@@ -470,44 +464,27 @@ def get_path(name, scheme=get_default_scheme(), vars=None, expand=True):
470464def _init_config_vars ():
471465 global _CONFIG_VARS
472466 _CONFIG_VARS = {}
473-
474- prefix = os .path .normpath (sys .prefix )
475- exec_prefix = os .path .normpath (sys .exec_prefix )
476- base_prefix = _BASE_PREFIX
477- base_exec_prefix = _BASE_EXEC_PREFIX
478-
479- try :
480- abiflags = sys .abiflags
481- except AttributeError :
482- abiflags = ''
483-
484- if os .name == 'posix' :
485- _init_posix (_CONFIG_VARS )
486- # If we are cross-compiling, load the prefixes from the Makefile instead.
487- if '_PYTHON_PROJECT_BASE' in os .environ :
488- prefix = _CONFIG_VARS ['prefix' ]
489- exec_prefix = _CONFIG_VARS ['exec_prefix' ]
490- base_prefix = _CONFIG_VARS ['prefix' ]
491- base_exec_prefix = _CONFIG_VARS ['exec_prefix' ]
492- abiflags = _CONFIG_VARS ['ABIFLAGS' ]
493-
494467 # Normalized versions of prefix and exec_prefix are handy to have;
495468 # in fact, these are the standard versions used most places in the
496469 # Distutils.
497- _CONFIG_VARS ['prefix' ] = prefix
498- _CONFIG_VARS ['exec_prefix' ] = exec_prefix
470+ _CONFIG_VARS ['prefix' ] = _PREFIX
471+ _CONFIG_VARS ['exec_prefix' ] = _EXEC_PREFIX
499472 _CONFIG_VARS ['py_version' ] = _PY_VERSION
500473 _CONFIG_VARS ['py_version_short' ] = _PY_VERSION_SHORT
501474 _CONFIG_VARS ['py_version_nodot' ] = _PY_VERSION_SHORT_NO_DOT
502- _CONFIG_VARS ['installed_base' ] = base_prefix
503- _CONFIG_VARS ['base' ] = prefix
504- _CONFIG_VARS ['installed_platbase' ] = base_exec_prefix
505- _CONFIG_VARS ['platbase' ] = exec_prefix
475+ _CONFIG_VARS ['installed_base' ] = _BASE_PREFIX
476+ _CONFIG_VARS ['base' ] = _PREFIX
477+ _CONFIG_VARS ['installed_platbase' ] = _BASE_EXEC_PREFIX
478+ _CONFIG_VARS ['platbase' ] = _EXEC_PREFIX
506479 _CONFIG_VARS ['projectbase' ] = _PROJECT_BASE
507480 _CONFIG_VARS ['platlibdir' ] = sys .platlibdir
508481 _CONFIG_VARS ['implementation' ] = _get_implementation ()
509482 _CONFIG_VARS ['implementation_lower' ] = _get_implementation ().lower ()
510- _CONFIG_VARS ['abiflags' ] = abiflags
483+ try :
484+ _CONFIG_VARS ['abiflags' ] = sys .abiflags
485+ except AttributeError :
486+ # sys.abiflags may not be defined on all platforms.
487+ _CONFIG_VARS ['abiflags' ] = ''
511488 try :
512489 _CONFIG_VARS ['py_version_nodot_plat' ] = sys .winver .replace ('.' , '' )
513490 except AttributeError :
@@ -516,6 +493,8 @@ def _init_config_vars():
516493 if os .name == 'nt' :
517494 _init_non_posix (_CONFIG_VARS )
518495 _CONFIG_VARS ['VPATH' ] = sys ._vpath
496+ if os .name == 'posix' :
497+ _init_posix (_CONFIG_VARS )
519498 if _HAS_USER_BASE :
520499 # Setting 'userbase' is done below the call to the
521500 # init function to enable using 'get_config_var' in
@@ -562,19 +541,9 @@ def get_config_vars(*args):
562541 With arguments, return a list of values that result from looking up
563542 each argument in the configuration variable dictionary.
564543 """
565- global _CONFIG_VARS_INITIALIZED
566544
567545 # Avoid claiming the lock once initialization is complete.
568- if _CONFIG_VARS_INITIALIZED :
569- # GH-126789: If sys.prefix or sys.exec_prefix were updated, invalidate the cache.
570- prefix = os .path .normpath (sys .prefix )
571- exec_prefix = os .path .normpath (sys .exec_prefix )
572- if _CONFIG_VARS ['prefix' ] != prefix or _CONFIG_VARS ['exec_prefix' ] != exec_prefix :
573- with _CONFIG_VARS_LOCK :
574- _CONFIG_VARS_INITIALIZED = False
575- _init_config_vars ()
576- else :
577- # Initialize the config_vars cache.
546+ if not _CONFIG_VARS_INITIALIZED :
578547 with _CONFIG_VARS_LOCK :
579548 # Test again with the lock held to avoid races. Note that
580549 # we test _CONFIG_VARS here, not _CONFIG_VARS_INITIALIZED,
0 commit comments