Issue #22826: The result of open() in Tools/freeze/bkfile.py is now better

compatible with regular files (in particular it now supports the context
management protocol).
This commit is contained in:
Serhiy Storchaka 2015-03-20 09:21:59 +02:00
parent 8490f5acfe
commit 53c3fb186a
4 changed files with 59 additions and 87 deletions

View file

@ -439,25 +439,17 @@ def main():
frozendllmain_c, os.path.basename(extensions_c)] + files
maindefn = checkextensions_win32.CExtension( '__main__', xtras )
frozen_extensions.append( maindefn )
outfp = open(makefile, 'w')
try:
with open(makefile, 'w') as outfp:
winmakemakefile.makemakefile(outfp,
locals(),
frozen_extensions,
os.path.basename(target))
finally:
outfp.close()
return
# generate config.c and Makefile
builtins.sort()
infp = open(config_c_in)
outfp = bkfile.open(config_c, 'w')
try:
with open(config_c_in) as infp, bkfile.open(config_c, 'w') as outfp:
makeconfig.makeconfig(infp, outfp, builtins)
finally:
outfp.close()
infp.close()
cflags = ['$(OPT)']
cppflags = defines + includes
@ -475,11 +467,8 @@ def main():
files + supp_sources + addfiles + libs + \
['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)']
outfp = bkfile.open(makefile, 'w')
try:
with bkfile.open(makefile, 'w') as outfp:
makemakefile.makemakefile(outfp, somevars, files, base_target)
finally:
outfp.close()
# Done!