This is a mirror of official site: http://jasper-net.blogspot.com/

Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip

| Wednesday, December 1, 2010
  In the jargon of the computer programmer, a hacker is someone who strives to solve problems in elegant and ingenious ways. Part of the path to elegantly solving larger problems is to use tools that solve sub-problems very well. For the modern Python programmer, some of the most important tools to aid in reduced complexity and repetition are virtualenv, Fabric, and pip. Although these tools have no strict relationship (in the sense that many people may use one or two of these tools often, yet aren't even aware of the others), they form a powerful suite when combined. An excellent example is the following:

You have a Django project that you want to do automated deployment to both your staging and production environment (Fabric). The project has several dependencies the need to be exactly met at deploy time (pip), and the remote production environment disallows global site-package installation, so you need an isolated environment to install all dependencies (virtualenv).

I have found virtualenv, pip, and Fabric together to be invaluable for my larger personal projects, Codenode and Wikipedia Game, but even for the smallest of projects, I always use at least one for something. In this article I will discuss the benefits and specifics of each of the three tools.

Note: In each example, it is recommended to consider replacing each usage of easy_install with a call to pip instead - it's just that easy_install is still more well known and prevalent. Ironically, an easy way of getting pip is by typing easy_install
pip, although there are other ways, see google. A discussion of the pip vs easy_install dilemma can be found in the last section entitled pip.


virtualenv

virtualenv is a great tool that creates isolated python environments, and is very easy to use. So easy in fact, you basically have little excused not to use it :-). Try switching over to your shell and typing exactly the following code:

easy_install virtualenv
virtualenv myvirtenv
cd myvirtenv
source bin/active

Badda-bing, you have used virtualenv!


Fabric
Fabric is all about minimizing the laborious repetition that is involved into taking local development code and putting it into a remote deployment environment. In practice, deploying always includes several very boring steps, and to quote an excellent article on deploying Django with Fabric:
  Repetition leads to boredom, boredom to horrifying mistakes, horrifying mistakes to God-I-wish-I-was-still-bored

pip
In my earlier example you saw me using easy_install, and what I'm about to preach is that in fact you should be using pip. Truth is, this mild taste of hypocrisy is because I myself am in a state of transition/exploration of whether I should completely adopt pip never look back.  pip is the future of Python package management, or at least that's what is seems like. Let's hear the arguments.


Read more: electronic.habitat : alex.clemesha

Posted via email from .NET Info

0 comments: