@@ -173,7 +173,9 @@ def joinuser(*args):
173
173
_PY_VERSION = sys .version .split ()[0 ]
174
174
_PY_VERSION_SHORT = f'{ sys .version_info [0 ]} .{ sys .version_info [1 ]} '
175
175
_PY_VERSION_SHORT_NO_DOT = f'{ sys .version_info [0 ]} { sys .version_info [1 ]} '
176
+ _PREFIX = os .path .normpath (sys .prefix )
176
177
_BASE_PREFIX = os .path .normpath (sys .base_prefix )
178
+ _EXEC_PREFIX = os .path .normpath (sys .exec_prefix )
177
179
_BASE_EXEC_PREFIX = os .path .normpath (sys .base_exec_prefix )
178
180
# Mutex guarding initialization of _CONFIG_VARS.
179
181
_CONFIG_VARS_LOCK = threading .RLock ()
@@ -316,22 +318,14 @@ def get_default_scheme():
316
318
317
319
def get_makefile_filename ():
318
320
"""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
-
324
321
if _PYTHON_BUILD :
325
322
return os .path .join (_PROJECT_BASE , "Makefile" )
326
-
327
323
if hasattr (sys , 'abiflags' ):
328
324
config_dir_name = f'config-{ _PY_VERSION_SHORT } { sys .abiflags } '
329
325
else :
330
326
config_dir_name = 'config'
331
-
332
327
if hasattr (sys .implementation , '_multiarch' ):
333
328
config_dir_name += f'-{ sys .implementation ._multiarch } '
334
-
335
329
return os .path .join (get_path ('stdlib' ), config_dir_name , 'Makefile' )
336
330
337
331
@@ -470,44 +464,27 @@ def get_path(name, scheme=get_default_scheme(), vars=None, expand=True):
470
464
def _init_config_vars ():
471
465
global _CONFIG_VARS
472
466
_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
-
494
467
# Normalized versions of prefix and exec_prefix are handy to have;
495
468
# in fact, these are the standard versions used most places in the
496
469
# 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
499
472
_CONFIG_VARS ['py_version' ] = _PY_VERSION
500
473
_CONFIG_VARS ['py_version_short' ] = _PY_VERSION_SHORT
501
474
_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
506
479
_CONFIG_VARS ['projectbase' ] = _PROJECT_BASE
507
480
_CONFIG_VARS ['platlibdir' ] = sys .platlibdir
508
481
_CONFIG_VARS ['implementation' ] = _get_implementation ()
509
482
_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' ] = ''
511
488
try :
512
489
_CONFIG_VARS ['py_version_nodot_plat' ] = sys .winver .replace ('.' , '' )
513
490
except AttributeError :
@@ -516,6 +493,8 @@ def _init_config_vars():
516
493
if os .name == 'nt' :
517
494
_init_non_posix (_CONFIG_VARS )
518
495
_CONFIG_VARS ['VPATH' ] = sys ._vpath
496
+ if os .name == 'posix' :
497
+ _init_posix (_CONFIG_VARS )
519
498
if _HAS_USER_BASE :
520
499
# Setting 'userbase' is done below the call to the
521
500
# init function to enable using 'get_config_var' in
@@ -562,19 +541,9 @@ def get_config_vars(*args):
562
541
With arguments, return a list of values that result from looking up
563
542
each argument in the configuration variable dictionary.
564
543
"""
565
- global _CONFIG_VARS_INITIALIZED
566
544
567
545
# 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 :
578
547
with _CONFIG_VARS_LOCK :
579
548
# Test again with the lock held to avoid races. Note that
580
549
# we test _CONFIG_VARS here, not _CONFIG_VARS_INITIALIZED,
0 commit comments