[Distutils] virtualenv and buildout integration ?

Jeff Rush jeff at taupro.com
Thu Aug 27 12:14:20 CEST 2009


Yonsy Solis wrote:
> 
> we recently began tu use virtualenv and buildout for development and
> deployments in some projects (more one internal effort to convince the
> ppl heads to use this for the next projects)
> 
> by now i have two ways to work.
> 
> 1) create a venv and inside this create the buildout dir project.
> 2) create a venv and in the same venv directory create the buildout
> tree.
> by now both options require to do two operations, first create the
> venv, activate this and after this create the buildout and run this.
> 
> i am thinking about develop an recipe/extension for buildout to:
> 
> - create a virtualenv
> - activate the venv
> - rerun the buildout using the ptyhon venv (bypassing the venv part)

Not quite the approach you propose but (in a french Monty Python and the
Holy Grail accent) "We're already got one." ;-)

Like you I need to initialize new projects often and tired of repeating
various steps.  One day I noticed that the virtualenv command is
extensible so I extended it to init a buildout after creating a sandbox.
 I also had it drop in some default files like a buildout.cfg with my
favorite options, license/README.txt files and the buildout bootstrap.py
that I always forget about.  The extension also changes the default
sandbox option to --no-site-packages since I use that most often.

You can find it at:

  https://www.dfwpython.org/repo/Projects/sandbox/mk_sandbox.py

To create your new command, run once with your chosen version of Python:

  $ python2.6 mk_sandbox.py
  $ cp sandbox /usr/local/bin/

now anytime I need a readymade project I run:

  $ sandbox projectx
  $ cd projectx
  (edit buildout.cfg)
  $ bin/buildout
  (make some changes)
  $ hg ci

It has some new command-line options as well.  I find it quite useful
during presentations when you need to spin up a workarea to illustrate
some concept spontaneously.

  $ sandbox --help
Usage: sandbox [OPTIONS] DEST_DIR

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity
  -q, --quiet           Decrease verbosity
  -p PYTHON_EXE, --python=PYTHON_EXE
                        The Python interpreter to use, e.g.,
                        --python=python2.5 will use the python2.5
                        interpreter to create the new environment.
                        The default is the interpreter that virtualenv
                        was installed with (/usr/bin/python2.6)
  --clear               Clear out the non-root install and start from
                        scratch
  --unzip-setuptools    Unzip Setuptools when installing it
  --relocatable         Make an EXISTING virtualenv environment
                        relocatable.  This fixes up scripts and makes
                        all .pth files relative
  --site-packages       Give access to the global site-packages dir to
                        the virtual environment
  --no-buildout         Omit installing zc.buildout into the sandbox
  --no-mercurial        Omit initializing a Mercurial repository in the
                        sandbox

-Jeff



More information about the Distutils-SIG mailing list