163 from mercurial import __version__ |
163 from mercurial import __version__ |
164 version = __version__.version |
164 version = __version__.version |
165 except ImportError: |
165 except ImportError: |
166 version = 'unknown' |
166 version = 'unknown' |
167 |
167 |
168 class install_package_data(install_data): |
|
169 def finalize_options(self): |
|
170 self.set_undefined_options('install', |
|
171 ('install_lib', 'install_dir')) |
|
172 install_data.finalize_options(self) |
|
173 |
|
174 class build_mo(build): |
168 class build_mo(build): |
175 |
169 |
176 description = "build translations (.mo files)" |
170 description = "build translations (.mo files)" |
177 |
171 |
178 def run(self): |
172 def run(self): |
191 if not po.endswith('.po'): |
185 if not po.endswith('.po'): |
192 continue |
186 continue |
193 pofile = join(podir, po) |
187 pofile = join(podir, po) |
194 modir = join('locale', po[:-3], 'LC_MESSAGES') |
188 modir = join('locale', po[:-3], 'LC_MESSAGES') |
195 mofile = join(modir, 'hg.mo') |
189 mofile = join(modir, 'hg.mo') |
196 cmd = ['msgfmt', '-v', '-o', mofile, pofile] |
190 mobuildfile = join('mercurial', mofile) |
|
191 cmd = ['msgfmt', '-v', '-o', mobuildfile, pofile] |
197 if sys.platform != 'sunos5': |
192 if sys.platform != 'sunos5': |
198 # msgfmt on Solaris does not know about -c |
193 # msgfmt on Solaris does not know about -c |
199 cmd.append('-c') |
194 cmd.append('-c') |
200 self.mkpath(modir) |
195 self.mkpath(join('mercurial', modir)) |
201 self.make_file([pofile], mofile, spawn, (cmd,)) |
196 self.make_file([pofile], mobuildfile, spawn, (cmd,)) |
202 self.distribution.data_files.append((join('mercurial', modir), |
197 |
203 [mofile])) |
198 # Insert build_mo first so that files in mercurial/locale/ are found |
204 |
199 # when build_py is run next. |
205 build.sub_commands.append(('build_mo', None)) |
200 build.sub_commands.insert(0, ('build_mo', None)) |
206 |
201 |
207 Distribution.pure = 0 |
202 Distribution.pure = 0 |
208 Distribution.global_options.append(('pure', None, "use pure (slow) Python " |
203 Distribution.global_options.append(('pure', None, "use pure (slow) Python " |
209 "code instead of C extensions")) |
204 "code instead of C extensions")) |
210 |
205 |
228 if module[1] != "__init__": |
223 if module[1] != "__init__": |
229 yield ("mercurial", module[1], module[2]) |
224 yield ("mercurial", module[1], module[2]) |
230 else: |
225 else: |
231 yield module |
226 yield module |
232 |
227 |
233 cmdclass = {'install_data': install_package_data, |
228 cmdclass = {'build_mo': build_mo, |
234 'build_mo': build_mo, |
|
235 'build_py': hg_build_py} |
229 'build_py': hg_build_py} |
236 |
230 |
237 ext_modules=[ |
231 ext_modules=[ |
238 Extension('mercurial.base85', ['mercurial/base85.c']), |
232 Extension('mercurial.base85', ['mercurial/base85.c']), |
239 Extension('mercurial.bdiff', ['mercurial/bdiff.c']), |
233 Extension('mercurial.bdiff', ['mercurial/bdiff.c']), |
253 if has_function(cc, 'inotify_add_watch'): |
247 if has_function(cc, 'inotify_add_watch'): |
254 ext_modules.append(Extension('hgext.inotify.linux._inotify', |
248 ext_modules.append(Extension('hgext.inotify.linux._inotify', |
255 ['hgext/inotify/linux/_inotify.c'])) |
249 ['hgext/inotify/linux/_inotify.c'])) |
256 packages.extend(['hgext.inotify', 'hgext.inotify.linux']) |
250 packages.extend(['hgext.inotify', 'hgext.inotify.linux']) |
257 |
251 |
|
252 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo', |
|
253 'help/*.txt']} |
|
254 |
|
255 def ordinarypath(p): |
|
256 return p and p[0] != '.' and p[-1] != '~' |
|
257 |
|
258 for root in ('templates', ): |
|
259 for curdir, dirs, files in os.walk(os.path.join('mercurial', root)): |
|
260 curdir = curdir.split(os.sep, 1)[1] |
|
261 dirs[:] = filter(ordinarypath, dirs) |
|
262 for f in filter(ordinarypath, files): |
|
263 f = os.path.join(curdir, f) |
|
264 packagedata['mercurial'].append(f) |
|
265 |
258 datafiles = [] |
266 datafiles = [] |
259 for root in ('templates', 'help'): |
|
260 for dir, dirs, files in os.walk(root): |
|
261 dirs[:] = [x for x in dirs if not x.startswith('.')] |
|
262 files = [x for x in files if not x.startswith('.')] |
|
263 datafiles.append((os.path.join('mercurial', dir), |
|
264 [os.path.join(dir, file_) for file_ in files])) |
|
265 |
267 |
266 setup(name='mercurial', |
268 setup(name='mercurial', |
267 version=version, |
269 version=version, |
268 author='Matt Mackall', |
270 author='Matt Mackall', |
269 author_email='mpm@selenic.com', |
271 author_email='mpm@selenic.com', |
272 license='GNU GPL', |
274 license='GNU GPL', |
273 scripts=scripts, |
275 scripts=scripts, |
274 packages=packages, |
276 packages=packages, |
275 ext_modules=ext_modules, |
277 ext_modules=ext_modules, |
276 data_files=datafiles, |
278 data_files=datafiles, |
|
279 package_data=packagedata, |
277 cmdclass=cmdclass, |
280 cmdclass=cmdclass, |
278 options=dict(py2exe=dict(packages=['hgext', 'email']), |
281 options=dict(py2exe=dict(packages=['hgext', 'email']), |
279 bdist_mpkg=dict(zipdist=True, |
282 bdist_mpkg=dict(zipdist=True, |
280 license='COPYING', |
283 license='COPYING', |
281 readme='contrib/macosx/Readme.html', |
284 readme='contrib/macosx/Readme.html', |