Mercurial > hg
diff setup.py @ 28977:740156eedf2c stable 3.8-rc
merge default into stable for 3.8 code freeze
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 16 Apr 2016 18:06:48 -0500 |
parents | 776fd2e2cf5a |
children | ee2e4a2c3690 |
line wrap: on
line diff
--- a/setup.py Tue Mar 29 11:54:46 2016 -0500 +++ b/setup.py Sat Apr 16 18:06:48 2016 -0500 @@ -84,19 +84,6 @@ from distutils.sysconfig import get_python_inc, get_config_var from distutils.version import StrictVersion -convert2to3 = '--c2to3' in sys.argv -if convert2to3: - try: - from distutils.command.build_py import build_py_2to3 as build_py - from lib2to3.refactor import get_fixers_from_package as getfixers - except ImportError: - if sys.version_info[0] < 3: - raise SystemExit("--c2to3 is only compatible with python3.") - raise - sys.path.append('contrib') -elif sys.version_info[0] >= 3: - raise SystemExit("setup.py with python3 needs --c2to3 (experimental)") - scripts = ['hg'] if os.name == 'nt': # We remove hg.bat if we are able to build hg.exe. @@ -220,30 +207,27 @@ version = kw.get('node', '')[:12] if version: - f = open("mercurial/__version__.py", "w") - f.write('# this file is autogenerated by setup.py\n') - f.write('version = "%s"\n' % version) - f.close() - + with open("mercurial/__version__.py", "w") as f: + f.write('# this file is autogenerated by setup.py\n') + f.write('version = "%s"\n' % version) try: + oldpolicy = os.environ.get('HGMODULEPOLICY', None) + os.environ['HGMODULEPOLICY'] = 'py' from mercurial import __version__ version = __version__.version except ImportError: version = 'unknown' +finally: + if oldpolicy is None: + del os.environ['HGMODULEPOLICY'] + else: + os.environ['HGMODULEPOLICY'] = oldpolicy class hgbuild(build): # Insert hgbuildmo first so that files in mercurial/locale/ are found # when build_py is run next. - sub_commands = [('build_mo', None), - - # We also need build_ext before build_py. Otherwise, when 2to3 is - # called (in build_py), it will not find osutil & friends, - # thinking that those modules are global and, consequently, making - # a mess, now that all module imports are global. - - ('build_ext', build.has_ext_modules), - ] + build.sub_commands + sub_commands = [('build_mo', None)] + build.sub_commands class hgbuildmo(build): @@ -282,8 +266,6 @@ global_options = Distribution.global_options + \ [('pure', None, "use pure (slow) Python " "code instead of C extensions"), - ('c2to3', None, "(experimental!) convert " - "code with 2to3"), ] def has_ext_modules(self): @@ -328,10 +310,6 @@ return build_scripts.run(self) class hgbuildpy(build_py): - if convert2to3: - fixer_names = sorted(set(getfixers("lib2to3.fixes") + - getfixers("hgfixes"))) - def finalize_options(self): build_py.finalize_options(self) @@ -343,21 +321,16 @@ raise SystemExit('Python headers are required to build ' 'Mercurial but weren\'t found in %s' % h) - def copy_file(self, *args, **kwargs): - dst, copied = build_py.copy_file(self, *args, **kwargs) + def run(self): + if self.distribution.pure: + modulepolicy = 'py' + else: + modulepolicy = 'c' + with open("mercurial/__modulepolicy__.py", "w") as f: + f.write('# this file is autogenerated by setup.py\n') + f.write('modulepolicy = "%s"\n' % modulepolicy) - if copied and dst.endswith('__init__.py'): - if self.distribution.pure: - modulepolicy = 'py' - else: - modulepolicy = 'c' - content = open(dst, 'rb').read() - content = content.replace(b'@MODULELOADPOLICY@', - modulepolicy.encode(libdir_escape)) - with open(dst, 'wb') as fh: - fh.write(content) - - return dst, copied + build_py.run(self) class buildhgextindex(Command): description = 'generate prebuilt index of hgext (for frozen package)' @@ -372,9 +345,8 @@ def run(self): if os.path.exists(self._indexfilename): - f = open(self._indexfilename, 'w') - f.write('# empty\n') - f.close() + with open(self._indexfilename, 'w') as f: + f.write('# empty\n') # here no extension enabled, disabled() lists up everything code = ('import pprint; from mercurial import extensions; ' @@ -383,11 +355,10 @@ if err: raise DistutilsExecError(err) - f = open(self._indexfilename, 'w') - f.write('# this file is autogenerated by setup.py\n') - f.write('docs = ') - f.write(out) - f.close() + with open(self._indexfilename, 'w') as f: + f.write('# this file is autogenerated by setup.py\n') + f.write('docs = ') + f.write(out) class buildhgexe(build_ext): description = 'compile hg.exe from mercurial/exewrapper.c' @@ -400,10 +371,9 @@ self.compiler.dll_libraries = [] # no -lmsrvc90 hv = sys.hexversion pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff) - f = open('mercurial/hgpythonlib.h', 'wb') - f.write('/* this file is autogenerated by setup.py */\n') - f.write('#define HGPYTHONLIB "%s"\n' % pythonlib) - f.close() + with open('mercurial/hgpythonlib.h', 'wb') as f: + f.write('/* this file is autogenerated by setup.py */\n') + f.write('#define HGPYTHONLIB "%s"\n' % pythonlib) objects = self.compiler.compile(['mercurial/exewrapper.c'], output_dir=self.build_temp) dir = os.path.dirname(self.get_ext_fullpath('dummy')) @@ -503,9 +473,8 @@ libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common):] for outfile in self.outfiles: - fp = open(outfile, 'rb') - data = fp.read() - fp.close() + with open(outfile, 'rb') as fp: + data = fp.read() # skip binary files if b'\0' in data: @@ -520,9 +489,8 @@ continue data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape)) - fp = open(outfile, 'wb') - fp.write(data) - fp.close() + with open(outfile, 'wb') as fp: + fp.write(data) cmdclass = {'build': hgbuild, 'build_mo': hgbuildmo, @@ -537,8 +505,9 @@ packages = ['mercurial', 'mercurial.hgweb', 'mercurial.httpclient', 'mercurial.pure', - 'hgext', 'hgext.convert', 'hgext.highlight', 'hgext.zeroconf', - 'hgext.largefiles'] + 'hgext', 'hgext.convert', 'hgext.fsmonitor', + 'hgext.fsmonitor.pywatchman', 'hgext.highlight', + 'hgext.largefiles', 'hgext.zeroconf', 'hgext3rd'] common_depends = ['mercurial/util.h'] @@ -564,6 +533,8 @@ Extension('mercurial.osutil', ['mercurial/osutil.c'], extra_link_args=osutil_ldflags, depends=common_depends), + Extension('hgext.fsmonitor.pywatchman.bser', + ['hgext/fsmonitor/pywatchman/bser.c']), ] try: