Thursday, January 6, 2011

pip, git and VirtualEnv

I've come across this problem twice now, where I work uses Gitorious to house our code repositories and we use pip to install packages and virtualenv to isolate those installations for development, test and production. The problem is with our current development work flow, we make clones of the package we are working on, on our local machine and work out of branches on that clone, pushing our changes back up to an identical branch on the remote repository. Looking through the documentation pip will allow you to install packages and modules from Gitorious with the following

 -e git://remote.repo/project/project.git@branch@egg=project

which works great on its own, but when you throw virutalenv in the mix this is where things get a little crazy.

I have my virtualenvs, using virtualenvwrapper, stored in my home in a hidden directory.

 ~/.virtualenvs

where the project's virtual env would be

 ~/.virtualenvs/project

and in the virtual env there is a 'src' directory

 ~/.virutalenvs/project/src

The problem is when I make some changes to a package that my project depends upon, using pip I remove the old version of the package

 pip uninstall old_package

and then using pip I install the updated package from Gitorious

pip -e git://remote.repo/package/package.git@branch@egg=package

I get an error stating

You are not currently on a branch, so I cannot use any
 'branch.merge' in your configuration file.
 Please specify whcih remote branch you want to use on the command
 line and try again (e.g. 'git pull ').
 See git-pull(1) for details.
    Complete output from command /usr/bin/git pull -q:

!? This had me running in circles for a couple ours until I realized two things, one if the egg is exploded in 'site-packages' the command 'pip uninstall package' does not remove this exploded directory, two virtualenv stores a full copy of the package source in

 ~/.virutalenvs/project/src/package

Removing the source code in both of these location allows me to use

pip -e git://remote.repo/package/package.git@branch@egg=package

without the error and all is good with the world. I'm just not sure where the bug is, and haven't filed a ticket yet to get the problem fixed. I'm not sure if the problem is with pip, virtualenv, virtualenvwrapper or our work flow and source control. I just hope this post helps some other folks.

2 comments:

  1. I was havign this issue, but I fixed it by updating to pip 1.0.2

    ReplyDelete
  2. I've changed jobs since this post and I can't remember what version of pip was on my old work machine. My new job doesn't use the same workflow, actually new job migrated from Subversion to Perforce... 8-S

    It's good to know that the problem has been addressed, thanks!

    ReplyDelete