复制/复制Django开发环境

时间:2011-08-11 15:39:00

标签: django development-environment buildout

我正和朋友们一起研究Django项目。该项目依赖于一些python模块。我有django和virtualenv中安装的那些额外的依赖项。 django项目的代码位于一个存储库中,可供所有可以签出/克隆然后为其提供代码的朋友访问。但是有没有办法在朋友的计算机中复制我在开发环境中的设置,即安装所有其他依赖项并准备部署环境的东西?

我听说过zc.buildout。只是看看它而不是太深。它看起来确实很复杂。还有其他方法可以实现这一目标吗?我朋友使用的开发环境从GNU / Linux到MS Windows不等。

2 个答案:

答案 0 :(得分:3)

virtualenv有一个简洁的功能,它可以创建一个带有更多钩子的副本。在你的情况下,重要的钩子是after_install,它将在安装virtualenv之后执行。

只需创建一个包含以下内容的脚本:

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)

执行它。它将创建一个bootstrap.py文件,您的伙伴必须执行该文件来引导virtualenv和所需的包:

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

virtualenv是在项目的根目录下创建的,所以一定要在提交之前svn:ignore或.gitignore创建的目录。

唯一的缺点是AFAIK没有与virtualenvwrapper集成。但无论如何,存在这样的存在理由是在项目中拥有环境,而virtualenvwrapper就是拥有你家乡的环境。

答案 1 :(得分:3)

buildout.cfg:

[buildout]
parts = python

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

获取bootstrap.py。然后:

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