1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
6
from fabric.api import env, local
7
from fabric.context_managers import lcd
9
from .constants import VIRTUALENV
12
def bootstrap(download_cache_path=None):
13
"""Bootstrap the development environment."""
15
install_dependencies(download_cache_path)
19
"""Clean up compiled and backup files."""
20
local("find . -name '*.~*' -delete")
21
local("find . -name '*.pyc' -delete")
24
def setup_virtualenv():
25
"""Create the virtualenv."""
27
virtual_env = os.environ.get('VIRTUAL_ENV', None)
28
if virtual_env is None:
29
if not os.path.exists(VIRTUALENV):
32
virtual_env = VIRTUALENV
33
env.virtualenv = os.path.abspath(virtual_env)
34
_activate_virtualenv()
38
def install_dependencies(download_cache_path=None):
39
"""Install all dependencies into the virtualenv."""
40
if download_cache_path:
42
with lcd(download_cache_path):
44
'make install PACKAGES="-r %s/requirements.txt"' %
47
virtualenv_local('pip install -r requirements.txt', capture=False)
50
def virtualenv_local(command, capture=True):
51
"""Run a command inside the virtualenv."""
53
virtual_env = env.get('virtualenv', None)
55
prefix = ". %s/bin/activate && " % virtual_env
56
command = prefix + command
57
return local(command, capture=capture)
60
def _activate_virtualenv():
61
"""Activate the virtualenv."""
62
activate_this = os.path.abspath(
63
"%s/bin/activate_this.py" % env.virtualenv)
64
execfile(activate_this, dict(__file__=activate_this))
67
def _create_virtualenv(clear=False):
68
"""Create the virtualenv."""
69
if not os.path.exists(VIRTUALENV) or clear:
70
virtualenv_bin_path = local('which virtualenv', capture=True)
71
virtualenv_version = local("%s %s --version" % (
72
sys.executable, virtualenv_bin_path), capture=True)
73
args = '--distribute --clear'
74
if virtualenv_version < '1.7':
75
args += ' --no-site-packages'
76
local("%s %s %s %s" % (sys.executable,
77
virtualenv_bin_path, args, VIRTUALENV),