30
31
ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
31
32
VENV = os.path.join(ROOT, '.nova-venv')
32
33
PIP_REQUIRES = os.path.join(ROOT, 'tools', 'pip-requires')
33
TWISTED_NOVA='http://nova.openstack.org/Twisted-10.0.0Nova.tar.gz'
34
TWISTED_NOVA = 'http://nova.openstack.org/Twisted-10.0.0Nova.tar.gz'
35
PY_VERSION = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
35
38
def die(message, *args):
36
print >>sys.stderr, message % args
39
print >> sys.stderr, message % args
43
def check_python_version():
44
if sys.version_info < (2, 6):
45
die("Need Python Version >= 2.6")
40
48
def run_command(cmd, redirect_output=True, check_exit_code=True):
42
Runs a command in an out-of-process shell, returning the
43
output of that command. Working directory is ROOT.
46
stdout = subprocess.PIPE
50
proc = subprocess.Popen(cmd, cwd=ROOT, stdout=stdout)
51
output = proc.communicate()[0]
52
if check_exit_code and proc.returncode != 0:
53
die('Command "%s" failed.\n%s', ' '.join(cmd), output)
57
HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'], check_exit_code=False).strip())
58
HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'], check_exit_code=False).strip())
50
Runs a command in an out-of-process shell, returning the
51
output of that command. Working directory is ROOT.
54
stdout = subprocess.PIPE
58
proc = subprocess.Popen(cmd, cwd=ROOT, stdout=stdout)
59
output = proc.communicate()[0]
60
if check_exit_code and proc.returncode != 0:
61
die('Command "%s" failed.\n%s', ' '.join(cmd), output)
65
HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'],
66
check_exit_code=False).strip())
67
HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'],
68
check_exit_code=False).strip())
61
71
def check_dependencies():
62
"""Make sure virtualenv is in the path."""
72
"""Make sure virtualenv is in the path."""
64
if not HAS_VIRTUALENV:
66
# Try installing it via easy_install...
68
print 'Installing virtualenv via easy_install...',
69
if not run_command(['which', 'easy_install']):
70
die('ERROR: virtualenv not found.\n\nNova development requires virtualenv,'
71
' please install it using your favorite package management tool')
74
if not HAS_VIRTUALENV:
76
# Try installing it via easy_install...
78
print 'Installing virtualenv via easy_install...',
79
if not (run_command(['which', 'easy_install']) and
80
run_command(['easy_install', 'virtualenv'])):
81
die('ERROR: virtualenv not found.\n\nNova development'
82
' requires virtualenv, please install it using your'
83
' favorite package management tool')
76
88
def create_virtualenv(venv=VENV):
77
"""Creates the virtual environment and installs PIP only into the
80
print 'Creating venv...',
81
run_command(['virtualenv', '-q', '--no-site-packages', VENV])
83
print 'Installing pip in virtualenv...',
84
if not run_command(['tools/with_venv.sh', 'easy_install', 'pip']).strip():
85
die("Failed to install pip.")
89
"""Creates the virtual environment and installs PIP only into the
92
print 'Creating venv...',
93
run_command(['virtualenv', '-q', '--no-site-packages', VENV])
95
print 'Installing pip in virtualenv...',
96
if not run_command(['tools/with_venv.sh', 'easy_install', 'pip']).strip():
97
die("Failed to install pip.")
89
101
def install_dependencies(venv=VENV):
90
print 'Installing dependencies with pip (this can take a while)...'
91
run_command(['tools/with_venv.sh', 'pip', 'install', '-E', venv, '-r', PIP_REQUIRES],
92
redirect_output=False)
93
run_command(['tools/with_venv.sh', 'pip', 'install', '-E', venv, TWISTED_NOVA],
94
redirect_output=False)
97
# Tell the virtual env how to "import nova"
98
pthfile = os.path.join(venv, "lib", "python2.6", "site-packages", "nova.pth")
99
f = open(pthfile, 'w')
100
f.write("%s\n" % ROOT)
102
print 'Installing dependencies with pip (this can take a while)...'
103
# Install greenlet by hand - just listing it in the requires file does not
104
# get it in stalled in the right order
105
run_command(['tools/with_venv.sh', 'pip', 'install', '-E', venv,
106
'greenlet'], redirect_output=False)
107
run_command(['tools/with_venv.sh', 'pip', 'install', '-E', venv, '-r',
108
PIP_REQUIRES], redirect_output=False)
109
run_command(['tools/with_venv.sh', 'pip', 'install', '-E', venv,
110
TWISTED_NOVA], redirect_output=False)
112
# Tell the virtual env how to "import nova"
113
pthfile = os.path.join(venv, "lib", PY_VERSION, "site-packages",
115
f = open(pthfile, 'w')
116
f.write("%s\n" % ROOT)
117
# Patch eventlet (see FAQ # 1485)
118
patchsrc = os.path.join(ROOT, 'tools', 'eventlet-patch')
119
patchfile = os.path.join(venv, "lib", PY_VERSION, "site-packages",
120
"eventlet", "green", "subprocess.py")
121
patch_cmd = "patch %s %s" % (patchfile, patchsrc)
103
125
def print_help():
105
Nova development environment setup is complete.
107
Nova development uses virtualenv to track and manage Python dependencies
108
while in development and testing.
110
To activate the Nova virtualenv for the extent of your current shell session
113
$ source .nova-venv/bin/activate
115
Or, if you prefer, you can run commands in the virtualenv on a case by case
118
$ tools/with_venv.sh <your command>
120
Also, make test will automatically use the virtualenv.
127
Nova development environment setup is complete.
129
Nova development uses virtualenv to track and manage Python dependencies
130
while in development and testing.
132
To activate the Nova virtualenv for the extent of your current shell
135
$ source .nova-venv/bin/activate
137
Or, if you prefer, you can run commands in the virtualenv on a case by case
140
$ tools/with_venv.sh <your command>
142
Also, make test will automatically use the virtualenv.
128
install_dependencies()
148
check_python_version()
151
install_dependencies()
131
154
if __name__ == '__main__':