##// END OF EJS Templates
setup: warn about missing standard Python components
Matt Mackall -
r7558:dc211ad8 default
parent child Browse files
Show More
@@ -1,144 +1,161 b''
1 1 #!/usr/bin/env python
2 2 #
3 3 # This is the mercurial setup script.
4 4 #
5 5 # 'python setup.py install', or
6 6 # 'python setup.py --help' for more options
7 7
8 8 import sys
9 9 if not hasattr(sys, 'version_info') or sys.version_info < (2, 3, 0, 'final'):
10 10 raise SystemExit("Mercurial requires python 2.3 or later.")
11 11
12 # Solaris Python packaging brain damage
13 try:
14 import hashlib
15 sha = hashlib.sha1()
16 except:
17 try:
18 import sha
19 except:
20 raise SystemExit(
21 "Couldn't import standard hashlib (incomplete Python install).")
22
23 try:
24 import zlib
25 except:
26 raise SystemExit(
27 "Couldn't import standard zlib (incomplete Python install).")
28
12 29 import os
13 30 import shutil
14 31 import tempfile
15 32 from distutils.core import setup, Extension
16 33 from distutils.command.install_data import install_data
17 34 from distutils.ccompiler import new_compiler
18 35
19 36 import mercurial.version
20 37
21 38 extra = {}
22 39 scripts = ['hg']
23 40 if os.name == 'nt':
24 41 scripts.append('contrib/win32/hg.bat')
25 42
26 43 # simplified version of distutils.ccompiler.CCompiler.has_function
27 44 # that actually removes its temporary files.
28 45 def has_function(cc, funcname):
29 46 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
30 47 devnull = oldstderr = None
31 48 try:
32 49 try:
33 50 fname = os.path.join(tmpdir, 'funcname.c')
34 51 f = open(fname, 'w')
35 52 f.write('int main(void) {\n')
36 53 f.write(' %s();\n' % funcname)
37 54 f.write('}\n')
38 55 f.close()
39 56 # Redirect stderr to /dev/null to hide any error messages
40 57 # from the compiler.
41 58 # This will have to be changed if we ever have to check
42 59 # for a function on Windows.
43 60 devnull = open('/dev/null', 'w')
44 61 oldstderr = os.dup(sys.stderr.fileno())
45 62 os.dup2(devnull.fileno(), sys.stderr.fileno())
46 63 objects = cc.compile([fname])
47 64 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
48 65 except:
49 66 return False
50 67 return True
51 68 finally:
52 69 if oldstderr is not None:
53 70 os.dup2(oldstderr, sys.stderr.fileno())
54 71 if devnull is not None:
55 72 devnull.close()
56 73 shutil.rmtree(tmpdir)
57 74
58 75 # py2exe needs to be installed to work
59 76 try:
60 77 import py2exe
61 78
62 79 # Help py2exe to find win32com.shell
63 80 try:
64 81 import modulefinder
65 82 import win32com
66 83 for p in win32com.__path__[1:]: # Take the path to win32comext
67 84 modulefinder.AddPackagePath("win32com", p)
68 85 pn = "win32com.shell"
69 86 __import__(pn)
70 87 m = sys.modules[pn]
71 88 for p in m.__path__[1:]:
72 89 modulefinder.AddPackagePath(pn, p)
73 90 except ImportError:
74 91 pass
75 92
76 93 extra['console'] = ['hg']
77 94
78 95 except ImportError:
79 96 pass
80 97
81 98 # specify version string, otherwise 'hg identify' will be used:
82 99 version = ''
83 100
84 101 class install_package_data(install_data):
85 102 def finalize_options(self):
86 103 self.set_undefined_options('install',
87 104 ('install_lib', 'install_dir'))
88 105 install_data.finalize_options(self)
89 106
90 107 mercurial.version.remember_version(version)
91 108 cmdclass = {'install_data': install_package_data}
92 109
93 110 ext_modules=[
94 111 Extension('mercurial.base85', ['mercurial/base85.c']),
95 112 Extension('mercurial.bdiff', ['mercurial/bdiff.c']),
96 113 Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c']),
97 114 Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
98 115 Extension('mercurial.parsers', ['mercurial/parsers.c']),
99 116 ]
100 117
101 118 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
102 119 'hgext.highlight', 'hgext.zeroconf', ]
103 120
104 121 try:
105 122 import msvcrt
106 123 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
107 124 except ImportError:
108 125 pass
109 126
110 127 try:
111 128 import posix
112 129 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
113 130
114 131 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
115 132 # The inotify extension is only usable with Linux 2.6 kernels.
116 133 # You also need a reasonably recent C library.
117 134 cc = new_compiler()
118 135 if has_function(cc, 'inotify_add_watch'):
119 136 ext_modules.append(Extension('hgext.inotify.linux._inotify',
120 137 ['hgext/inotify/linux/_inotify.c']))
121 138 packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
122 139 except ImportError:
123 140 pass
124 141
125 142 setup(name='mercurial',
126 143 version=mercurial.version.get_version(),
127 144 author='Matt Mackall',
128 145 author_email='mpm@selenic.com',
129 146 url='http://selenic.com/mercurial',
130 147 description='Scalable distributed SCM',
131 148 license='GNU GPL',
132 149 scripts=scripts,
133 150 packages=packages,
134 151 ext_modules=ext_modules,
135 152 data_files=[(os.path.join('mercurial', root),
136 153 [os.path.join(root, file_) for file_ in files])
137 154 for root, dirs, files in os.walk('templates')],
138 155 cmdclass=cmdclass,
139 156 options=dict(py2exe=dict(packages=['hgext', 'email']),
140 157 bdist_mpkg=dict(zipdist=True,
141 158 license='COPYING',
142 159 readme='contrib/macosx/Readme.html',
143 160 welcome='contrib/macosx/Welcome.html')),
144 161 **extra)
General Comments 0
You need to be logged in to leave comments. Login now