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