##// END OF EJS Templates
setup: switch to with open as...
timeless -
r28418:121d2571 default
parent child Browse files
Show More
@@ -207,11 +207,9 b" elif os.path.exists('.hg_archival.txt'):"
207 version = kw.get('node', '')[:12]
207 version = kw.get('node', '')[:12]
208
208
209 if version:
209 if version:
210 f = open("mercurial/__version__.py", "w")
210 with open("mercurial/__version__.py", "w") as f:
211 f.write('# this file is autogenerated by setup.py\n')
211 f.write('# this file is autogenerated by setup.py\n')
212 f.write('version = "%s"\n' % version)
212 f.write('version = "%s"\n' % version)
213 f.close()
214
215
213
216 try:
214 try:
217 from mercurial import __version__
215 from mercurial import __version__
@@ -345,9 +343,8 b' class buildhgextindex(Command):'
345
343
346 def run(self):
344 def run(self):
347 if os.path.exists(self._indexfilename):
345 if os.path.exists(self._indexfilename):
348 f = open(self._indexfilename, 'w')
346 with open(self._indexfilename, 'w') as f:
349 f.write('# empty\n')
347 f.write('# empty\n')
350 f.close()
351
348
352 # here no extension enabled, disabled() lists up everything
349 # here no extension enabled, disabled() lists up everything
353 code = ('import pprint; from mercurial import extensions; '
350 code = ('import pprint; from mercurial import extensions; '
@@ -356,11 +353,10 b' class buildhgextindex(Command):'
356 if err:
353 if err:
357 raise DistutilsExecError(err)
354 raise DistutilsExecError(err)
358
355
359 f = open(self._indexfilename, 'w')
356 with open(self._indexfilename, 'w') as f:
360 f.write('# this file is autogenerated by setup.py\n')
357 f.write('# this file is autogenerated by setup.py\n')
361 f.write('docs = ')
358 f.write('docs = ')
362 f.write(out)
359 f.write(out)
363 f.close()
364
360
365 class buildhgexe(build_ext):
361 class buildhgexe(build_ext):
366 description = 'compile hg.exe from mercurial/exewrapper.c'
362 description = 'compile hg.exe from mercurial/exewrapper.c'
@@ -373,10 +369,9 b' class buildhgexe(build_ext):'
373 self.compiler.dll_libraries = [] # no -lmsrvc90
369 self.compiler.dll_libraries = [] # no -lmsrvc90
374 hv = sys.hexversion
370 hv = sys.hexversion
375 pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff)
371 pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff)
376 f = open('mercurial/hgpythonlib.h', 'wb')
372 with open('mercurial/hgpythonlib.h', 'wb') as f:
377 f.write('/* this file is autogenerated by setup.py */\n')
373 f.write('/* this file is autogenerated by setup.py */\n')
378 f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
374 f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
379 f.close()
380 objects = self.compiler.compile(['mercurial/exewrapper.c'],
375 objects = self.compiler.compile(['mercurial/exewrapper.c'],
381 output_dir=self.build_temp)
376 output_dir=self.build_temp)
382 dir = os.path.dirname(self.get_ext_fullpath('dummy'))
377 dir = os.path.dirname(self.get_ext_fullpath('dummy'))
@@ -476,9 +471,8 b' class hginstallscripts(install_scripts):'
476 libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common):]
471 libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common):]
477
472
478 for outfile in self.outfiles:
473 for outfile in self.outfiles:
479 fp = open(outfile, 'rb')
474 with open(outfile, 'rb') as fp:
480 data = fp.read()
475 data = fp.read()
481 fp.close()
482
476
483 # skip binary files
477 # skip binary files
484 if b'\0' in data:
478 if b'\0' in data:
@@ -493,9 +487,8 b' class hginstallscripts(install_scripts):'
493 continue
487 continue
494
488
495 data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
489 data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
496 fp = open(outfile, 'wb')
490 with open(outfile, 'wb') as fp:
497 fp.write(data)
491 fp.write(data)
498 fp.close()
499
492
500 cmdclass = {'build': hgbuild,
493 cmdclass = {'build': hgbuild,
501 'build_mo': hgbuildmo,
494 'build_mo': hgbuildmo,
General Comments 0
You need to be logged in to leave comments. Login now