Show More
@@ -1,208 +1,211 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # This is the mercurial setup script. |
|
3 | # This is the mercurial setup script. | |
4 | # |
|
4 | # | |
5 | # 'python setup.py install', or |
|
5 | # 'python setup.py install', or | |
6 | # 'python setup.py --help' for more options |
|
6 | # 'python setup.py --help' for more options | |
7 |
|
7 | |||
8 | import sys |
|
8 | import sys | |
9 | if not hasattr(sys, 'version_info') or sys.version_info < (2, 3, 0, 'final'): |
|
9 | if not hasattr(sys, 'version_info') or sys.version_info < (2, 3, 0, 'final'): | |
10 | raise SystemExit("Mercurial requires python 2.3 or later.") |
|
10 | raise SystemExit("Mercurial requires python 2.3 or later.") | |
11 |
|
11 | |||
12 | # Solaris Python packaging brain damage |
|
12 | # Solaris Python packaging brain damage | |
13 | try: |
|
13 | try: | |
14 | import hashlib |
|
14 | import hashlib | |
15 | sha = hashlib.sha1() |
|
15 | sha = hashlib.sha1() | |
16 | except: |
|
16 | except: | |
17 | try: |
|
17 | try: | |
18 | import sha |
|
18 | import sha | |
19 | except: |
|
19 | except: | |
20 | raise SystemExit( |
|
20 | raise SystemExit( | |
21 | "Couldn't import standard hashlib (incomplete Python install).") |
|
21 | "Couldn't import standard hashlib (incomplete Python install).") | |
22 |
|
22 | |||
23 | try: |
|
23 | try: | |
24 | import zlib |
|
24 | import zlib | |
25 | except: |
|
25 | except: | |
26 | raise SystemExit( |
|
26 | raise SystemExit( | |
27 | "Couldn't import standard zlib (incomplete Python install).") |
|
27 | "Couldn't import standard zlib (incomplete Python install).") | |
28 |
|
28 | |||
29 | import os, time |
|
29 | import os, time | |
30 | import shutil |
|
30 | import shutil | |
31 | import tempfile |
|
31 | import tempfile | |
32 | from distutils.core import setup, Extension |
|
32 | from distutils.core import setup, Extension | |
33 | from distutils.command.install_data import install_data |
|
33 | from distutils.command.install_data import install_data | |
34 | from distutils.command.build import build |
|
34 | from distutils.command.build import build | |
35 | from distutils.spawn import spawn, find_executable |
|
35 | from distutils.spawn import spawn, find_executable | |
36 | from distutils.ccompiler import new_compiler |
|
36 | from distutils.ccompiler import new_compiler | |
37 |
|
37 | |||
38 | extra = {} |
|
38 | extra = {} | |
39 | scripts = ['hg'] |
|
39 | scripts = ['hg'] | |
40 | if os.name == 'nt': |
|
40 | if os.name == 'nt': | |
41 | scripts.append('contrib/win32/hg.bat') |
|
41 | scripts.append('contrib/win32/hg.bat') | |
42 |
|
42 | |||
43 | # simplified version of distutils.ccompiler.CCompiler.has_function |
|
43 | # simplified version of distutils.ccompiler.CCompiler.has_function | |
44 | # that actually removes its temporary files. |
|
44 | # that actually removes its temporary files. | |
45 | def has_function(cc, funcname): |
|
45 | def has_function(cc, funcname): | |
46 | tmpdir = tempfile.mkdtemp(prefix='hg-install-') |
|
46 | tmpdir = tempfile.mkdtemp(prefix='hg-install-') | |
47 | devnull = oldstderr = None |
|
47 | devnull = oldstderr = None | |
48 | try: |
|
48 | try: | |
49 | try: |
|
49 | try: | |
50 | fname = os.path.join(tmpdir, 'funcname.c') |
|
50 | fname = os.path.join(tmpdir, 'funcname.c') | |
51 | f = open(fname, 'w') |
|
51 | f = open(fname, 'w') | |
52 | f.write('int main(void) {\n') |
|
52 | f.write('int main(void) {\n') | |
53 | f.write(' %s();\n' % funcname) |
|
53 | f.write(' %s();\n' % funcname) | |
54 | f.write('}\n') |
|
54 | f.write('}\n') | |
55 | f.close() |
|
55 | f.close() | |
56 | # Redirect stderr to /dev/null to hide any error messages |
|
56 | # Redirect stderr to /dev/null to hide any error messages | |
57 | # from the compiler. |
|
57 | # from the compiler. | |
58 | # This will have to be changed if we ever have to check |
|
58 | # This will have to be changed if we ever have to check | |
59 | # for a function on Windows. |
|
59 | # for a function on Windows. | |
60 | devnull = open('/dev/null', 'w') |
|
60 | devnull = open('/dev/null', 'w') | |
61 | oldstderr = os.dup(sys.stderr.fileno()) |
|
61 | oldstderr = os.dup(sys.stderr.fileno()) | |
62 | os.dup2(devnull.fileno(), sys.stderr.fileno()) |
|
62 | os.dup2(devnull.fileno(), sys.stderr.fileno()) | |
63 | objects = cc.compile([fname]) |
|
63 | objects = cc.compile([fname]) | |
64 | cc.link_executable(objects, os.path.join(tmpdir, "a.out")) |
|
64 | cc.link_executable(objects, os.path.join(tmpdir, "a.out")) | |
65 | except: |
|
65 | except: | |
66 | return False |
|
66 | return False | |
67 | return True |
|
67 | return True | |
68 | finally: |
|
68 | finally: | |
69 | if oldstderr is not None: |
|
69 | if oldstderr is not None: | |
70 | os.dup2(oldstderr, sys.stderr.fileno()) |
|
70 | os.dup2(oldstderr, sys.stderr.fileno()) | |
71 | if devnull is not None: |
|
71 | if devnull is not None: | |
72 | devnull.close() |
|
72 | devnull.close() | |
73 | shutil.rmtree(tmpdir) |
|
73 | shutil.rmtree(tmpdir) | |
74 |
|
74 | |||
75 | # py2exe needs to be installed to work |
|
75 | # py2exe needs to be installed to work | |
76 | try: |
|
76 | try: | |
77 | import py2exe |
|
77 | import py2exe | |
78 |
|
78 | |||
79 | # Help py2exe to find win32com.shell |
|
79 | # Help py2exe to find win32com.shell | |
80 | try: |
|
80 | try: | |
81 | import modulefinder |
|
81 | import modulefinder | |
82 | import win32com |
|
82 | import win32com | |
83 | for p in win32com.__path__[1:]: # Take the path to win32comext |
|
83 | for p in win32com.__path__[1:]: # Take the path to win32comext | |
84 | modulefinder.AddPackagePath("win32com", p) |
|
84 | modulefinder.AddPackagePath("win32com", p) | |
85 | pn = "win32com.shell" |
|
85 | pn = "win32com.shell" | |
86 | __import__(pn) |
|
86 | __import__(pn) | |
87 | m = sys.modules[pn] |
|
87 | m = sys.modules[pn] | |
88 | for p in m.__path__[1:]: |
|
88 | for p in m.__path__[1:]: | |
89 | modulefinder.AddPackagePath(pn, p) |
|
89 | modulefinder.AddPackagePath(pn, p) | |
90 | except ImportError: |
|
90 | except ImportError: | |
91 | pass |
|
91 | pass | |
92 |
|
92 | |||
93 | extra['console'] = ['hg'] |
|
93 | extra['console'] = ['hg'] | |
94 |
|
94 | |||
95 | except ImportError: |
|
95 | except ImportError: | |
96 | pass |
|
96 | pass | |
97 |
|
97 | |||
98 | try: |
|
98 | try: | |
99 | l = os.popen('hg id -it').read().split() |
|
99 | l = os.popen('hg id -it').read().split() | |
100 | while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags |
|
100 | while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags | |
101 | l.pop() |
|
101 | l.pop() | |
102 | version = l and l[-1] or 'unknown' # latest tag or revision number |
|
102 | version = l and l[-1] or 'unknown' # latest tag or revision number | |
103 | if version.endswith('+'): |
|
103 | if version.endswith('+'): | |
104 | version += time.strftime('%Y%m%d') |
|
104 | version += time.strftime('%Y%m%d') | |
105 |
|
105 | |||
106 | except OSError: |
|
106 | except OSError: | |
107 | version = "unknown" |
|
107 | version = "unknown" | |
108 |
|
108 | |||
109 | f = file("mercurial/__version__.py", "w") |
|
109 | f = file("mercurial/__version__.py", "w") | |
110 | f.write('# this file is autogenerated by setup.py\n') |
|
110 | f.write('# this file is autogenerated by setup.py\n') | |
111 | f.write('version = "%s"\n' % version) |
|
111 | f.write('version = "%s"\n' % version) | |
112 | f.close() |
|
112 | f.close() | |
113 |
|
113 | |||
114 | class install_package_data(install_data): |
|
114 | class install_package_data(install_data): | |
115 | def finalize_options(self): |
|
115 | def finalize_options(self): | |
116 | self.set_undefined_options('install', |
|
116 | self.set_undefined_options('install', | |
117 | ('install_lib', 'install_dir')) |
|
117 | ('install_lib', 'install_dir')) | |
118 | install_data.finalize_options(self) |
|
118 | install_data.finalize_options(self) | |
119 |
|
119 | |||
120 | class build_mo(build): |
|
120 | class build_mo(build): | |
121 |
|
121 | |||
122 | description = "build translations (.mo files)" |
|
122 | description = "build translations (.mo files)" | |
123 |
|
123 | |||
124 | def run(self): |
|
124 | def run(self): | |
125 | if not find_executable('msgfmt'): |
|
125 | if not find_executable('msgfmt'): | |
126 | self.warn("could not find msgfmt executable, no translations " |
|
126 | self.warn("could not find msgfmt executable, no translations " | |
127 | "will be built") |
|
127 | "will be built") | |
128 | return |
|
128 | return | |
129 |
|
129 | |||
130 | podir = 'i18n' |
|
130 | podir = 'i18n' | |
131 | if not os.path.isdir(podir): |
|
131 | if not os.path.isdir(podir): | |
132 | self.warn("could not find %s/ directory" % podir) |
|
132 | self.warn("could not find %s/ directory" % podir) | |
133 | return |
|
133 | return | |
134 |
|
134 | |||
135 | join = os.path.join |
|
135 | join = os.path.join | |
136 | for po in os.listdir(podir): |
|
136 | for po in os.listdir(podir): | |
137 | if not po.endswith('.po'): |
|
137 | if not po.endswith('.po'): | |
138 | continue |
|
138 | continue | |
139 | pofile = join(podir, po) |
|
139 | pofile = join(podir, po) | |
140 | modir = join('locale', po[:-3], 'LC_MESSAGES') |
|
140 | modir = join('locale', po[:-3], 'LC_MESSAGES') | |
141 | mofile = join(modir, 'hg.mo') |
|
141 | mofile = join(modir, 'hg.mo') | |
|
142 | cmd = ['msgfmt', '-v', '-o', mofile, pofile] | |||
|
143 | if sys.platform != 'sunos5': | |||
|
144 | # msgfmt on Solaris does not know about -c | |||
|
145 | cmd.append('-c') | |||
142 | self.mkpath(modir) |
|
146 | self.mkpath(modir) | |
143 | self.make_file([pofile], mofile, spawn, |
|
147 | self.make_file([pofile], mofile, spawn, (cmd,)) | |
144 | (['msgfmt', '-v', '-c', '-o', mofile, pofile],)) |
|
|||
145 | self.distribution.data_files.append((join('mercurial', modir), |
|
148 | self.distribution.data_files.append((join('mercurial', modir), | |
146 | [mofile])) |
|
149 | [mofile])) | |
147 |
|
150 | |||
148 | build.sub_commands.append(('build_mo', None)) |
|
151 | build.sub_commands.append(('build_mo', None)) | |
149 |
|
152 | |||
150 | cmdclass = {'install_data': install_package_data, |
|
153 | cmdclass = {'install_data': install_package_data, | |
151 | 'build_mo': build_mo} |
|
154 | 'build_mo': build_mo} | |
152 |
|
155 | |||
153 | ext_modules=[ |
|
156 | ext_modules=[ | |
154 | Extension('mercurial.base85', ['mercurial/base85.c']), |
|
157 | Extension('mercurial.base85', ['mercurial/base85.c']), | |
155 | Extension('mercurial.bdiff', ['mercurial/bdiff.c']), |
|
158 | Extension('mercurial.bdiff', ['mercurial/bdiff.c']), | |
156 | Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c']), |
|
159 | Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c']), | |
157 | Extension('mercurial.mpatch', ['mercurial/mpatch.c']), |
|
160 | Extension('mercurial.mpatch', ['mercurial/mpatch.c']), | |
158 | Extension('mercurial.parsers', ['mercurial/parsers.c']), |
|
161 | Extension('mercurial.parsers', ['mercurial/parsers.c']), | |
159 | ] |
|
162 | ] | |
160 |
|
163 | |||
161 | packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert', |
|
164 | packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert', | |
162 | 'hgext.highlight', 'hgext.zeroconf', ] |
|
165 | 'hgext.highlight', 'hgext.zeroconf', ] | |
163 |
|
166 | |||
164 | try: |
|
167 | try: | |
165 | import msvcrt |
|
168 | import msvcrt | |
166 | ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'])) |
|
169 | ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'])) | |
167 | except ImportError: |
|
170 | except ImportError: | |
168 | pass |
|
171 | pass | |
169 |
|
172 | |||
170 | try: |
|
173 | try: | |
171 | import posix |
|
174 | import posix | |
172 | ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'])) |
|
175 | ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'])) | |
173 |
|
176 | |||
174 | if sys.platform == 'linux2' and os.uname()[2] > '2.6': |
|
177 | if sys.platform == 'linux2' and os.uname()[2] > '2.6': | |
175 | # The inotify extension is only usable with Linux 2.6 kernels. |
|
178 | # The inotify extension is only usable with Linux 2.6 kernels. | |
176 | # You also need a reasonably recent C library. |
|
179 | # You also need a reasonably recent C library. | |
177 | cc = new_compiler() |
|
180 | cc = new_compiler() | |
178 | if has_function(cc, 'inotify_add_watch'): |
|
181 | if has_function(cc, 'inotify_add_watch'): | |
179 | ext_modules.append(Extension('hgext.inotify.linux._inotify', |
|
182 | ext_modules.append(Extension('hgext.inotify.linux._inotify', | |
180 | ['hgext/inotify/linux/_inotify.c'])) |
|
183 | ['hgext/inotify/linux/_inotify.c'])) | |
181 | packages.extend(['hgext.inotify', 'hgext.inotify.linux']) |
|
184 | packages.extend(['hgext.inotify', 'hgext.inotify.linux']) | |
182 | except ImportError: |
|
185 | except ImportError: | |
183 | pass |
|
186 | pass | |
184 |
|
187 | |||
185 | datafiles = [] |
|
188 | datafiles = [] | |
186 | for root in ('templates', 'i18n'): |
|
189 | for root in ('templates', 'i18n'): | |
187 | for dir, dirs, files in os.walk(root): |
|
190 | for dir, dirs, files in os.walk(root): | |
188 | datafiles.append((os.path.join('mercurial', dir), |
|
191 | datafiles.append((os.path.join('mercurial', dir), | |
189 | [os.path.join(dir, file_) for file_ in files])) |
|
192 | [os.path.join(dir, file_) for file_ in files])) | |
190 |
|
193 | |||
191 | setup(name='mercurial', |
|
194 | setup(name='mercurial', | |
192 | version=version, |
|
195 | version=version, | |
193 | author='Matt Mackall', |
|
196 | author='Matt Mackall', | |
194 | author_email='mpm@selenic.com', |
|
197 | author_email='mpm@selenic.com', | |
195 | url='http://selenic.com/mercurial', |
|
198 | url='http://selenic.com/mercurial', | |
196 | description='Scalable distributed SCM', |
|
199 | description='Scalable distributed SCM', | |
197 | license='GNU GPL', |
|
200 | license='GNU GPL', | |
198 | scripts=scripts, |
|
201 | scripts=scripts, | |
199 | packages=packages, |
|
202 | packages=packages, | |
200 | ext_modules=ext_modules, |
|
203 | ext_modules=ext_modules, | |
201 | data_files=datafiles, |
|
204 | data_files=datafiles, | |
202 | cmdclass=cmdclass, |
|
205 | cmdclass=cmdclass, | |
203 | options=dict(py2exe=dict(packages=['hgext', 'email']), |
|
206 | options=dict(py2exe=dict(packages=['hgext', 'email']), | |
204 | bdist_mpkg=dict(zipdist=True, |
|
207 | bdist_mpkg=dict(zipdist=True, | |
205 | license='COPYING', |
|
208 | license='COPYING', | |
206 | readme='contrib/macosx/Readme.html', |
|
209 | readme='contrib/macosx/Readme.html', | |
207 | welcome='contrib/macosx/Welcome.html')), |
|
210 | welcome='contrib/macosx/Welcome.html')), | |
208 | **extra) |
|
211 | **extra) |
General Comments 0
You need to be logged in to leave comments.
Login now