Mercurial > hg
comparison setup.py @ 12661:10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
This provides two new features:
- Mercurial may be installed into a non-standard location without
having to set PYTHONPATH.
- Multiple installations can use Mercurial from different locations.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Tue, 17 Aug 2010 15:44:38 +0200 |
parents | 6c0e1aee1b19 |
children | ef500b2f100b |
comparison
equal
deleted
inserted
replaced
12660:6ed5ae6264c2 | 12661:10da5a1f25dd |
---|---|
50 from distutils.core import setup, Extension | 50 from distutils.core import setup, Extension |
51 from distutils.dist import Distribution | 51 from distutils.dist import Distribution |
52 from distutils.command.build import build | 52 from distutils.command.build import build |
53 from distutils.command.build_ext import build_ext | 53 from distutils.command.build_ext import build_ext |
54 from distutils.command.build_py import build_py | 54 from distutils.command.build_py import build_py |
55 from distutils.command.install_scripts import install_scripts | |
55 from distutils.spawn import spawn, find_executable | 56 from distutils.spawn import spawn, find_executable |
56 from distutils.ccompiler import new_compiler | 57 from distutils.ccompiler import new_compiler |
57 from distutils.errors import CCompilerError | 58 from distutils.errors import CCompilerError |
58 from distutils.sysconfig import get_python_inc | 59 from distutils.sysconfig import get_python_inc |
59 | 60 |
214 # msgfmt on Solaris does not know about -c | 215 # msgfmt on Solaris does not know about -c |
215 cmd.append('-c') | 216 cmd.append('-c') |
216 self.mkpath(join('mercurial', modir)) | 217 self.mkpath(join('mercurial', modir)) |
217 self.make_file([pofile], mobuildfile, spawn, (cmd,)) | 218 self.make_file([pofile], mobuildfile, spawn, (cmd,)) |
218 | 219 |
220 | |
219 # Insert hgbuildmo first so that files in mercurial/locale/ are found | 221 # Insert hgbuildmo first so that files in mercurial/locale/ are found |
220 # when build_py is run next. | 222 # when build_py is run next. |
221 build.sub_commands.insert(0, ('build_mo', None)) | 223 build.sub_commands.insert(0, ('build_mo', None)) |
222 | 224 |
223 Distribution.pure = 0 | 225 Distribution.pure = 0 |
258 if module[1] != "__init__": | 260 if module[1] != "__init__": |
259 yield ("mercurial", module[1], module[2]) | 261 yield ("mercurial", module[1], module[2]) |
260 else: | 262 else: |
261 yield module | 263 yield module |
262 | 264 |
265 class hginstallscripts(install_scripts): | |
266 ''' | |
267 This is a specialization of install_scripts that replaces the @LIBDIR@ with | |
268 the configured directory for modules. If possible, the path is made relative | |
269 to the directory for scripts. | |
270 ''' | |
271 | |
272 def initialize_options(self): | |
273 install_scripts.initialize_options(self) | |
274 | |
275 self.install_lib = None | |
276 | |
277 def finalize_options(self): | |
278 install_scripts.finalize_options(self) | |
279 self.set_undefined_options('install', | |
280 ('install_lib', 'install_lib')) | |
281 | |
282 def run(self): | |
283 install_scripts.run(self) | |
284 | |
285 if (os.path.splitdrive(self.install_dir)[0] != | |
286 os.path.splitdrive(self.install_lib)[0]): | |
287 # can't make relative paths from one drive to another, so use an | |
288 # absolute path instead | |
289 libdir = self.install_lib | |
290 else: | |
291 common = os.path.commonprefix((self.install_dir, self.install_lib)) | |
292 rest = self.install_dir[len(common):] | |
293 uplevel = len([n for n in os.path.split(rest) if n]) | |
294 | |
295 libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common):] | |
296 | |
297 for outfile in self.outfiles: | |
298 data = open(outfile, 'rb').read() | |
299 | |
300 # skip binary files | |
301 if '\0' in data: | |
302 continue | |
303 | |
304 data = data.replace('@LIBDIR@', libdir) | |
305 open(outfile, 'wb').write(data) | |
306 | |
263 cmdclass = {'build_mo': hgbuildmo, | 307 cmdclass = {'build_mo': hgbuildmo, |
264 'build_ext': hgbuildext, | 308 'build_ext': hgbuildext, |
265 'build_py': hgbuildpy} | 309 'build_py': hgbuildpy, |
310 'install_scripts': hginstallscripts} | |
266 | 311 |
267 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert', | 312 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert', |
268 'hgext.highlight', 'hgext.zeroconf'] | 313 'hgext.highlight', 'hgext.zeroconf'] |
269 | 314 |
270 pymodules = [] | 315 pymodules = [] |