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