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