Monday, November 30, 2009

Vitualenv And Pip

I'm adapting to virtualenv and pip as part of my Python development environment. You use virtualenv to convert your development tree into a virtual Python environment, sandboxed from the rest of the system. You still run the system Python interpreter, but it finds modules installed in the virtualenv first. Basically, pip is a package manager which allows you to add and remove Python modules. But pip has one feature that sold me on the idea.

I mostly write command line utilities in Python. For the more complex commands, I usually write functional tests which required hard coding the executable path to ensure that tests run the correct command. In addition, you have to fiddle with the Python module search path to ensure the command's library modules can be found. It's not hard, but it is inelegant and not very portable.

The key feature is that pip can convert your development tree into a Python egg inside the virtualenv. The process installs the command under test into the virtualenv /bin directory and makes it's modules available in the normal Python search path. The tests can now safely execute the command without any special setup.

Yes, it seems like a small thing. But anything that makes the code simpler, is a good thing.

No comments:

Post a Comment