BitWorking

Mercurial, SSH, and a local install

I have the latest and greatest version of Mercurial on my laptop but the other machines I want to 'push' to over ssh are either a shared host without Mercurial installed or are pinned to a release of a distro that has a very old version of Mercurial. This means that I had to $ make install-home, which leaves me with a problem, which is that the installed Mercurial files won't be on my Python path when I ssh in. That means I see this when I ssh in from my laptop:

$ ssh bitworking.org /home/jcgregorio/bin/hg
Traceback (most recent call last):
  File "/home/jcgregorio/bin/hg", line 14, in ?
    from mercurial import demandimport; demandimport.enable()
ImportError: No module named mercurial
~
$ 

The easiest way I found to fix this to add the following two lines to the beginning of ~/bin/hg on the server:

import sys
sys.path.append('/home/jcgregorio/lib/python')

Then I need to specify the exact location of hg from the command line on the laptop, so it uses my locally installed version on the server:

$ hg push --remotecmd ~/bin/hg ssh://bitworking.org/myproject/

That --remotecmd can be made to go away if I add it to the config file for the project on the laptop. I created the file .hg/hgrc and added the following lines:

[ui]
remotecmd = ~/bin/hg

Now I can finally run:

$ hg push ssh://bitworking.org/myproject/
I solved the problem by adding a couple of lines to .profile (or .bash_profile or whatever) on my shared host:

export PATH=~/bin:$PATH
export PYTHONPATH=~/lib/python:$PYTHONPATH

You might have to adjust that PYTHONPATH value, though. Depending on the way you installed Mercurial, it's probably something more like ~/lib/python2.5/site-packages. Is there a reason this won't work for you?

Posted by Will on 2008-07-31

Will,

It would probably work, but it's rather invasive as that change would then apply to everything that runs over ssh.

Posted by Joe Gregorio on 2008-07-31

I, too, went the invasive route.

I don't have root, but ~/bin contains all the executables that I have installed, and ~/lib/python contains all of the python libraries. Since all of them are available to me when I ssh in, I can simply forget about the difference between system wide installation and per user installation. As none of them have been modified, upgrading is a snap.

Posted by Sam Ruby on 2008-07-31

Like Sam, I went the invasive route on purpose, because I wanted the software and Python libs I had installed myself to always be used rather than the system-wide software. Though you could make it slightly less invasive by sticking your personal bin and lib dirs at the end of the search paths:

export PATH=$PATH:~/bin
export PYTHONPATH=$PYTHONPATH:~/lib/python

That way your local software/libraries would only be used if they were not available system-wide. (I know I'm telling you stuff that you already know... for some reason, I felt compelled to spell all this out. Sorry!)

Posted by Will on 2008-07-31

Will,

(I know I'm telling you stuff that you already know... for some reason, I felt compelled to spell all this out. Sorry!)

NP, the reason I wrote this up is for people who were looking for a solution. If they come here and find a few alternatives, all the better!

Posted by Joe Gregorio on 2008-07-31

2008-07-31