diff options
author | Trent Nelson <trent@trent.me> | 2012-10-17 22:05:27 (GMT) |
---|---|---|
committer | Trent Nelson <trent@trent.me> | 2012-10-17 22:05:27 (GMT) |
commit | c78649873fe76da34230bb8ee5284ff64b2af2e4 (patch) | |
tree | 4106a277053364205adf49dbdb993d518f2ebe5d /Lib/sysconfig.py | |
parent | 284529dcf437b650eb72e92b88608e60aa90e10f (diff) | |
parent | ecbe2a91850516e41715885e6688e31935ed8f2c (diff) | |
download | cpython-c78649873fe76da34230bb8ee5284ff64b2af2e4.zip cpython-c78649873fe76da34230bb8ee5284ff64b2af2e4.tar.gz cpython-c78649873fe76da34230bb8ee5284ff64b2af2e4.tar.bz2 |
Merge issue #15298.
Diffstat (limited to 'Lib/sysconfig.py')
-rw-r--r-- | Lib/sysconfig.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index cf6b2db..e06e82a 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -377,24 +377,29 @@ def _generate_posix_vars(): # `make pybuilddir.txt` target -- which is a precursor to the # _sysconfigdata.py module being constructed. Unfortunately, # get_config_vars() eventually calls _init_posix(), which attempts - # to import _sysconfigdata, which we won't have built yet. So, - # write out _sysconfigdata.py to the current directory first, - # then call get_platform() to get the pybuilddir, then move it. - destfile = '_sysconfigdata.py' - with open(destfile, 'w', encoding='utf8') as f: - f.write('# system configuration generated and used by' - ' the sysconfig module\n') - f.write('build_time_vars = ') - pprint.pprint(vars, stream=f) + # to import _sysconfigdata, which we won't have built yet. In order + # for _init_posix() to work, if we're on Darwin, just mock up the + # _sysconfigdata module manually and populate it with the build vars. + # This is more than sufficient for ensuring the subsequent call to + # get_platform() succeeds. + name = '_sysconfigdata' + if 'darwin' in sys.platform: + import imp + module = imp.new_module(name) + module.build_time_vars = vars + sys.modules[name] = module pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3]) if hasattr(sys, "gettotalrefcount"): pybuilddir += '-pydebug' os.makedirs(pybuilddir, exist_ok=True) - target = os.path.join(pybuilddir, destfile) + destfile = os.path.join(pybuilddir, name + '.py') - # Relocate _sysconfigdata.py into its final home. - os.rename(destfile, target) + with open(destfile, 'w', encoding='utf8') as f: + f.write('# system configuration generated and used by' + ' the sysconfig module\n') + f.write('build_time_vars = ') + pprint.pprint(vars, stream=f) # Create file used for sys.path fixup -- see Modules/getpath.c with open('pybuilddir.txt', 'w', encoding='ascii') as f: |