Replicating/reproducing the Django development environment

后端 未结 2 792
伪装坚强ぢ
伪装坚强ぢ 2021-01-21 00:52

I am working with my friends on a Django project. The project has dependencies on some python modules. I have django and those additional dependencies installed inside a virtual

相关标签:
2条回答
  • 2021-01-21 01:06

    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.

    0 讨论(0)
  • 2021-01-21 01:19

    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 ...
    
    0 讨论(0)
提交回复
热议问题