Posted by fabriziogiudici
on July 22, 2009 at 5:09 AM PDT
After more than one year of experience with Mercurial (because NetBeans repository moved to hg time ago), I feel good with it and I've decided to switch most of my projects from Subversion to it. I'll talk in another post about the advantages of Mercurial over Subversion; today I'd like to share a solution to a problem that I've found.
Of course, all my projects are CIed under Hudson, so I need Mercurial on my Hudson server. My Hudson server is hosted in a virtual Linux host, where I don't have a full Linux setup and, of course, I don't have root access. Before asking to my provider for installing Mercurial on the system, I decided to check whether it is possible to install Mercurial in a non-root directory. It is possible, of course, as it doesn't require root privileges. The hard part is how to pack together all the Mercurial and Python stuff without getting crazy (and without learning anything about Python but the essential).
Fortunately, there's a thing named virtual-python that does the job of populating a user defined directory with all the python stuff, that you can later use to install Mercurial into. Since many people in the Linux world still don't get the point of having a portable VM, unfortunately installing Mercurial into a Python environment requires running the gcc compiler (everything is automated, but it's so old-fashioned from the past century). On my virtual host I don't have gcc, of course, but I solved this by preparing all the stuff on a Linux computer I own (of course, with the same 32/64 bit arch of the target).
In short, this is the sequence of commands you need:
sudo apt-get install python2.4 python2.4-dev
python2.4 virtual-python.py --prefix $HOME/python2.4/
wget sh" title="http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c9-py2.4.egg
sh">http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c9-py2.4.... setuptools-0.6c9-py2.4.egg --prefix=$HOME/python2.4/
python2.4/bin/easy_install-2.4 --prefix $HOME/python2.4/ mercurial
find python2.4 -type d | xargs chmod a+rx
find python2.4 -type f | xargs chmod a+r
tar cvzhf hg.tgz python2.4/
rm -rf python2.4 setuptools-0.6c9-py2.4.egg virtual-python.py
I suggest you create a new, temporary user so you work in a clean environment. At the end, you find a hg.tgz file with all the needed stuff (both Python, Mercurial and the required packages; note the 'h' switch for the tar command, that instead of following symbolic links to the original Python installation directories dumped the file contents).
I just copied the tarball to my virtual host and expanded under my home, then created this simple wrapper script:
and pointed Hudson to it. I also edited python2.4/bin/hg so the "dang bash" line is #!/home/fgiudici/python2.4/bin/python in place of #!/usr/bin/python2.4. It just works.
I think it would be nice that Hudson was able to automagically install Mercurial, as it is already capable to do this thing with tools such as Ant and Maven. I've filed a RFE for this feature .
PS Why Python 2.4? I suppose because I know it's enough for Mercurial, I think that the same procedure will work with more recent versions.