@@ -390,18 +390,31 @@ def _generate_posix_vars():
390390 if _PYTHON_BUILD :
391391 vars ['LDSHARED' ] = vars ['BLDSHARED' ]
392392
393- pybuilddir = 'build/lib.%s-%s' % (get_platform (), sys .version [:3 ])
394- if hasattr (sys , "gettotalrefcount" ):
395- pybuilddir += '-pydebug'
396- os .makedirs (pybuilddir , exist_ok = True )
397- destfile = os .path .join (pybuilddir , '_sysconfigdata.py' )
398-
393+ # There's a chicken-and-egg situation on OS X with regards to the
394+ # _sysconfigdata module after the changes introduced by #15298:
395+ # get_config_vars() is called by get_platform() as part of the
396+ # `make pybuilddir.txt` target -- which is a precursor to the
397+ # _sysconfigdata.py module being constructed. Unfortunately,
398+ # get_config_vars() eventually calls _init_posix(), which attempts
399+ # to import _sysconfigdata, which we won't have built yet. So,
400+ # write out _sysconfigdata.py to the current directory first,
401+ # then call get_platform() to get the pybuilddir, then move it.
402+ destfile = '_sysconfigdata.py'
399403 with open (destfile , 'w' , encoding = 'utf8' ) as f :
400404 f .write ('# system configuration generated and used by'
401405 ' the sysconfig module\n ' )
402406 f .write ('build_time_vars = ' )
403407 pprint .pprint (vars , stream = f )
404408
409+ pybuilddir = 'build/lib.%s-%s' % (get_platform (), sys .version [:3 ])
410+ if hasattr (sys , "gettotalrefcount" ):
411+ pybuilddir += '-pydebug'
412+ os .makedirs (pybuilddir , exist_ok = True )
413+ target = os .path .join (pybuilddir , destfile )
414+
415+ # Relocate _sysconfigdata.py into its final home.
416+ os .rename (destfile , target )
417+
405418 # Create file used for sys.path fixup -- see Modules/getpath.c
406419 with open ('pybuilddir.txt' , 'w' , encoding = 'ascii' ) as f :
407420 f .write (pybuilddir )
0 commit comments