[Django]-Replicating/reproducing the Django development environment

3👍

buildout.cfg:

[buildout]
parts = python

[python]
recipe = zc.recipe.egg
eggs =
    your
    egg
    dependencies
    here
interpreter = python

Get bootstrap.py. Then:

$ python bootstrap.py
$ bin/buildout
$ bin/python ...

3👍

virtualenv has a neat feature in which it creates a copy of itself with a couple more hooks. In your case the important hook is after_install, which will be executed just after the virtualenv is installed.

Just create a script with the following content:

import os, virtualenv

extra_text = """
import os, subprocess
def after_install(options, home_dir):
    subprocess.call([
        os.path.join(home_dir, 'bin', 'pip'),
        'install',
        '-r', 
        'relative_path_from_env_home_to_requirements_file',
    ])

def adjust_options(options, args):
    if not args: args.append('.')
"""

output = virtualenv.create_bootstrap_script(extra_text)
open('bootstrap.py', 'w').write(output)

And execute it. It will create a bootstrap.py file that your fellow must execute to bootstrap both the virtualenv and the required packages:

./bootstrap.py --no-site-packages

The virtualenv is created at the root of the project, so be sure to svn:ignore or .gitignore the created dirs before committing.

The only drawback of this is that AFAIK it’s not integrated with virtualenvwrapper. But anyway the raison d’être of this is to have the environment in the project, and the one of virtualenvwrapper is to have the environments in your homedir.

Leave a comment