diff options
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 188 |
1 files changed, 56 insertions, 132 deletions
@@ -5,7 +5,7 @@ # 'python setup.py --help' for more options import sys, platform -if getattr(sys, 'version_info', (0, 0, 0)) < (2, 4, 0, 'final'): +if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'): raise SystemExit("Mercurial requires Python 2.4 or later.") if sys.version_info[0] >= 3: @@ -23,19 +23,35 @@ else: try: import hashlib sha = hashlib.sha1() -except ImportError: +except: try: import sha - except ImportError: + except: raise SystemExit( "Couldn't import standard hashlib (incomplete Python install).") try: import zlib -except ImportError: +except: raise SystemExit( "Couldn't import standard zlib (incomplete Python install).") +# The base IronPython distribution (as of 2.7.1) doesn't support bz2 +isironpython = False +try: + isironpython = platform.python_implementation().lower().find("ironpython") != -1 +except: + pass + +if isironpython: + print "warning: IronPython detected (no bz2 support)" +else: + try: + import bz2 + except: + raise SystemExit( + "Couldn't import standard bz2 (incomplete Python install).") + import os, subprocess, time import shutil import tempfile @@ -48,24 +64,10 @@ from distutils.command.build_py import build_py from distutils.command.install_scripts import install_scripts from distutils.spawn import spawn, find_executable from distutils.ccompiler import new_compiler -from distutils import cygwinccompiler from distutils.errors import CCompilerError, DistutilsExecError from distutils.sysconfig import get_python_inc 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': scripts.append('contrib/win32/hg.bat') @@ -92,7 +94,7 @@ def hasfunction(cc, funcname): os.dup2(devnull.fileno(), sys.stderr.fileno()) objects = cc.compile([fname], output_dir=tmpdir) cc.link_executable(objects, os.path.join(tmpdir, "a.out")) - except Exception: + except: return False return True finally: @@ -106,22 +108,14 @@ def hasfunction(cc, funcname): try: import py2exe py2exeloaded = True - # import py2exe's patched Distribution class - from distutils.core import Distribution except ImportError: py2exeloaded = False def runcmd(cmd, env): - if sys.platform == 'plan9': - # subprocess kludge to work around issues in half-baked Python - # ports, notably bichued/python: - _, out, err = os.popen3(cmd) - return str(out), str(err) - else: - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, env=env) - out, err = p.communicate() - return out, err + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, env=env) + out, err = p.communicate() + return out, err def runhg(cmd, env): out, err = runcmd(cmd, env) @@ -139,22 +133,21 @@ def runhg(cmd, env): version = '' -# Execute hg out of this directory with a custom environment which -# includes the pure Python modules in mercurial/pure. We also take -# care to not use any hgrc files and do no localization. -pypath = ['mercurial', os.path.join('mercurial', 'pure')] -env = {'PYTHONPATH': os.pathsep.join(pypath), - 'HGRCPATH': '', - 'LANGUAGE': 'C'} -if 'LD_LIBRARY_PATH' in os.environ: - env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH'] -if 'SystemRoot' in os.environ: - # Copy SystemRoot into the custom environment for Python 2.6 - # under Windows. Otherwise, the subprocess will fail with - # error 0xc0150004. See: http://bugs.python.org/issue3440 - env['SystemRoot'] = os.environ['SystemRoot'] - if os.path.isdir('.hg'): + # Execute hg out of this directory with a custom environment which + # includes the pure Python modules in mercurial/pure. We also take + # care to not use any hgrc files and do no localization. + pypath = ['mercurial', os.path.join('mercurial', 'pure')] + env = {'PYTHONPATH': os.pathsep.join(pypath), + 'HGRCPATH': '', + 'LANGUAGE': 'C'} + if 'LD_LIBRARY_PATH' in os.environ: + env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH'] + if 'SystemRoot' in os.environ: + # Copy SystemRoot into the custom environment for Python 2.6 + # under Windows. Otherwise, the subprocess will fail with + # error 0xc0150004. See: http://bugs.python.org/issue3440 + env['SystemRoot'] = os.environ['SystemRoot'] cmd = [sys.executable, 'hg', 'id', '-i', '-t'] l = runhg(cmd, env).split() while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags @@ -192,19 +185,6 @@ try: except ImportError: version = 'unknown' -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 - class hgbuildmo(build): description = "build translations (.mo files)" @@ -236,20 +216,13 @@ class hgbuildmo(build): self.make_file([pofile], mobuildfile, spawn, (cmd,)) -class hgdist(Distribution): - pure = 0 +# Insert hgbuildmo first so that files in mercurial/locale/ are found +# when build_py is run next. +build.sub_commands.insert(0, ('build_mo', None)) - 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): - # self.ext_modules is emptied in hgbuildpy.finalize_options which is - # too late for some cases - return not self.pure and Distribution.has_ext_modules(self) +Distribution.pure = 0 +Distribution.global_options.append(('pure', None, "use pure (slow) Python " + "code instead of C extensions")) class hgbuildext(build_ext): @@ -263,9 +236,6 @@ class hgbuildext(build_ext): ext.name) class hgbuildpy(build_py): - if convert2to3: - fixer_names = sorted(set(getfixers("lib2to3.fixes") + - getfixers("hgfixes"))) def finalize_options(self): build_py.finalize_options(self) @@ -279,8 +249,7 @@ class hgbuildpy(build_py): self.distribution.ext_modules = [] else: if not os.path.exists(os.path.join(get_python_inc(), 'Python.h')): - raise SystemExit('Python headers are required to build ' - 'Mercurial') + raise SystemExit("Python headers are required to build Mercurial") def find_modules(self): modules = build_py.find_modules(self) @@ -319,25 +288,6 @@ class buildhgextindex(Command): f.write(out) f.close() -class buildhgexe(build_ext): - description = 'compile hg.exe from mercurial/exewrapper.c' - - def build_extensions(self): - if os.name != 'nt': - return - if isinstance(self.compiler, HackedMingw32CCompiler): - self.compiler.compiler_so = self.compiler.compiler # no -mdll - self.compiler.dll_libraries = [] # no -lmsrvc90 - objects = self.compiler.compile(['mercurial/exewrapper.c'], - output_dir=self.build_temp) - dir = os.path.dirname(self.get_ext_fullpath('dummy')) - target = os.path.join(dir, 'hg') - pythonlib = ("python%d%d" % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) - self.compiler.link_executable(objects, target, - libraries=[pythonlib], - output_dir=self.build_temp) - class hginstallscripts(install_scripts): ''' This is a specialization of install_scripts that replaces the @LIBDIR@ with @@ -376,7 +326,7 @@ class hginstallscripts(install_scripts): fp.close() # skip binary files - if b('\0') in data: + if '\0' in data: continue data = data.replace('@LIBDIR@', libdir.encode('string_escape')) @@ -384,18 +334,15 @@ class hginstallscripts(install_scripts): fp.write(data) fp.close() -cmdclass = {'build': hgbuild, - 'build_mo': hgbuildmo, +cmdclass = {'build_mo': hgbuildmo, 'build_ext': hgbuildext, 'build_py': hgbuildpy, 'build_hgextindex': buildhgextindex, - 'install_scripts': hginstallscripts, - 'build_hgexe': buildhgexe, - } + 'install_scripts': hginstallscripts} -packages = ['mercurial', 'mercurial.hgweb', 'mercurial.httpclient', - 'hgext', 'hgext.convert', 'hgext.highlight', 'hgext.zeroconf', - 'hgext.largefiles'] +packages = ['mercurial', 'mercurial.hgweb', + 'mercurial.httpclient', 'mercurial.httpclient.tests', + 'hgext', 'hgext.convert', 'hgext.highlight', 'hgext.zeroconf'] pymodules = [] @@ -419,20 +366,6 @@ else: extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'], extra_link_args=osutil_ldflags)) -# the -mno-cygwin option has been deprecated for years -Mingw32CCompiler = cygwinccompiler.Mingw32CCompiler - -class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler): - def __init__(self, *args, **kwargs): - Mingw32CCompiler.__init__(self, *args, **kwargs) - for i in 'compiler compiler_so linker_exe linker_so'.split(): - try: - getattr(self, i).remove('-mno-cygwin') - except ValueError: - pass - -cygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler - if sys.platform.startswith('linux') and os.uname()[2] > '2.6': # The inotify extension is only usable with Linux 2.6 kernels. # You also need a reasonably recent C library. @@ -480,18 +413,10 @@ if os.name == 'nt': if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'): # XCode 4.0 dropped support for ppc architecture, which is hardcoded in # distutils.sysconfig - version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[0].splitlines() - if version: - version = version[0] - xcode4 = (version.startswith('Xcode') and - StrictVersion(version.split()[1]) >= StrictVersion('4.0')) - else: - # xcodebuild returns empty on OS X Lion with XCode 4.3 not - # installed, but instead with only command-line tools. Assume - # that only happens on >= Lion, thus no PPC support. - xcode4 = True - - if xcode4: + version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[0].splitlines()[0] + # Also parse only first digit, because 3.2.1 can't be parsed nicely + if (version.startswith('Xcode') and + StrictVersion(version.split()[1]) >= StrictVersion('4.0')): os.environ['ARCHFLAGS'] = '' setup(name='mercurial', @@ -508,7 +433,6 @@ setup(name='mercurial', data_files=datafiles, package_data=packagedata, cmdclass=cmdclass, - distclass=hgdist, options=dict(py2exe=dict(packages=['hgext', 'email']), bdist_mpkg=dict(zipdist=True, license='COPYING', |