Friday, June 27, 2008

Installing mercurial on a shared web-hosting account (such as Dreamhost)

I've got a Dreamhost account, they offer oodles of disk space, and I want to set up a mercurial repository. The problem is they don't install mercurial as a system-wide thingy. Further it appears python prefers to have all python extensions installed as system-wide thingies (I don't use python and don't know it's ins and outs and idioms). Since I don't know the python idioms that leaves me to go by the mercurial documentation.

On the mercurial wiki they offer prebuilt packages for various packaging systems (.deb or .rpm etc) and they have an "easy install" method for Any system with modern Python and SetupTools installed. It certainly sounds simple to do

easy_install -U mercurial

Going to the EasyInstall home page we find a that installing this script presumes

  • You are installling to Python's primary site-packages directory
  • You have unrestricted system access on the computer where you are installing.

However the typical shared hosting account doesn't allow access to the site-packages directory. Now what? Reading on installing to Custom Locations does have the answer. Specifically the virtual python method.

Once you run virtual-python.py (downloaded from the above page) it creates directories in your $HOME named lib, include and bin which are set up to add stuff to the system python. You can run the regular system python and it will see the regular system python configuration, and you can run ~/bin/python and it will see the additional stuff you've installed in your local python.

Installing virtual python goes like this:-

wget <a href="http://peak.telecommunity.com/dist/virtual-python.py<br />
python" title="http://peak.telecommunity.com/dist/virtual-python.py<br />
python"><a href="http://peak.telecommunity.com/dist/virtual-python.py">http://peak.telecommunity.com/dist/virtual-python.py</a><br />
python</a> virtual-python.py 

This creates ~/bin and ~/lib directories with a shadow copy of python. Once you do this it's helpful to ensure your PATH variable contains ~/bin at the front, a useful step to take since it ensures you can use any command you put there.

Next follow the setuptools setup directions for your platform. For a Linux host I did this:-

wget http:.../setuptools-0.6c11-py2.4.egg
export PYTHONPATH=$HOME/lib/python2.4/site-packages
sh setuptools-0.6c11-py2.4.egg --prefix=~

Setting PYTHONPATH was required because of an error message it gave me. It's helpful to set this environment variable in your login environment.

This step may be useful, or might not be useful. Running setuptools seems to make this step unnecessary.

~/bin/python ez_setup.py

This sets up the easy installer in your local python. Then going back to the mercurial instructions you can now run the following. It may be required to add "--prefix=~" to this command.

~/bin/easy_install -U mercurial

Note that this time I prefixed '~/bin/' to the command. It's possible to set this python as the default simply by doing this:-

export PATH=$HOME/bin:${PATH}
or
setenv PATH $HOME/bin:${PATH}

Which command you use depends on your shell, of course. It seems the easy_install script adds this command for you to your login environment scripts. In any case once a 'bin' directory is enabled in your home directory you can of course also use it for other scripts, and they'll be automatically available as commands in your shell.