19

I currently have git and virtualenv set up in a way which exactly suits my needs and, so far, hasn't caused any problems. However I'm aware that my setup is non-standard and I'm wondering if anyone more familiar with virtualenv's internals can point out if, and where, it's likely to go wrong.

My setup

My virtualenv is inside my git repository, but git is set to ignore the bin and include directories and everything in lib except for the site-packages directory.

More precisely, my .gitignore file looks like this:

*.pyc

# Ignore all the virtualenv stuff except the actual packages
# themselves
/bin
/include
/lib/python*/*
!/lib/python*/site-packages

# Ignore easyinstall and setuptools
/lib/python*/site-packages/easy-install.pth
/lib/python*/site-packages/setuptools.pth
/lib/python*/site-packages/setuptools-*
/lib/python*/site-packages/pip-*

With this arrangement I -- and anyone else working on a checkout of the project -- can use virtualenv and pip as normal but with the following advantages:

  1. If anyone updates or installs a package and pushes their changes, anyone else who pulls those changes automatically gets the update: they don't need to notice that a requirements.txt file has changed or do any post-receive hook magic.

  2. There are no network dependencies: all the code to make the application work lives in the git repository.

I'm aware that this only works with pure-Python packages, but that's all I'm concerned with at the moment.

Does anyone know of any other problems with this approach that I should be aware of?

D. Evans
  • 3,242
  • 22
  • 23

3 Answers3

10

This is an interesting question. I think the other two answers (thus far) raise good specific points. Clearly you've thought this through and have arrived at a solution you like, but I'll note that there does seem to be a philosophical split here among virtualenv users.

One camp, to which I'd guess you belong, feels that the local VE is part of the project (i.e. it should be under version control). The other feels that the VE should essentially be treated as a development artifact -- that requirements.txt should be part of the project repo, but that you should be able to blow away and recreate the VE as needed.

I just mention this because when I first saw this distinction made, it helped shape my thinking about virtualenv. (I'm in the second camp, FWIW, because it seems simpler and cleaner to me, but that's not to say that being in the first camp is wrong for your particular project.)

Paul Bissex
  • 1,611
  • 1
  • 17
  • 22
  • 3
    Yes, you're completely right about this philosophical split. Although, obviously, the "check it all in" approach only really makes sense for projects where you fully control the runtime environment (as is the case for most web-based projects), and not for projects that are going to be run by many different users. Personally, I can see the arguments on both sides - at this stage I'm just trying to work out the practical consequences of one particular approach. – D. Evans May 16 '11 at 10:21
6

If you have any -e items in your requirements.txt - in other words if you have any editable dependencies as described in the format that are using the git version control system you will most likely run into issues when your src directory is committed. If you just add /src to your .gitignore then you can avoid this problem, but often the installation just adds a pointer in site-packages to this location, so you need it!

Henry
  • 6,502
  • 2
  • 24
  • 30
  • That's very helpful, thanks. I can see that this might be problematic. I'll have to go and experiment. – D. Evans May 16 '11 at 10:36
2

In /lib/python2.7/site-packages in my virtualenv I have absolute paths, for example in Django.egg-link I have /Users/henry/.virtualenv/mowapp/src/django (this is a Mac).

Check to see if you have any absolute paths checked into git, I think that is a major problem with this approach.

Henry
  • 6,502
  • 2
  • 24
  • 30
  • Thanks for this. Absolute paths were the first thing I checked for, and so far I haven't hit any - whether this is just a fluke of the particular packages I happen to have installed I don't know. From the paths you mentioned, it looks like you're using virtualenvwrapper which I'd imagine wouldn't play nicely with my approach. – D. Evans May 16 '11 at 10:30