1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
# You can obtain one at http://mozilla.org/MPL/2.0/.
5
# This file contains code for populating the virtualenv environment for
6
# Mozilla's build system. It is typically called as part of configure.
8
from __future__ import with_statement
12
import distutils.sysconfig
14
def populate_virtualenv(top_source_directory, manifest_filename):
15
"""Populate the virtualenv from the contents of a manifest.
17
The manifest file consists of colon-delimited fields. The first field
18
specifies the action. The remaining fields are arguments to that action.
19
The following actions are supported:
21
setup.py -- Invoke setup.py for a package. Expects the arguments:
22
1. relative path directory containing setup.py.
23
2. argument(s) to setup.py. e.g. "develop". Each program argument is
24
delimited by a colon. Arguments with colons are not yet supported.
26
Note that the Python interpreter running this function should be the one
27
from the virtualenv. If it is the system Python or if the environment is
28
not configured properly, packages could be installed into the wrong place.
29
This is how virtualenv's work.
32
fh = open(manifest_filename, 'rU')
34
packages.append(line.rstrip().split(':'))
37
for package in packages:
38
if package[0] == 'setup.py':
39
assert len(package) >= 2
41
call_setup(os.path.join(top_source_directory, package[1]),
43
if package[0].endswith('.pth'):
44
assert len(package) == 2
46
with open(os.path.join(distutils.sysconfig.get_python_lib(), package[0]), 'a') as f:
47
f.write("%s\n" % os.path.join(top_source_directory, package[1]))
49
def call_setup(directory, arguments):
50
"""Calls setup.py in a directory."""
51
setup = os.path.join(directory, 'setup.py')
53
program = [sys.executable, setup]
54
program.extend(arguments)
56
# We probably could call the contents of this file inside the context of
57
# this interpreter using execfile() or similar. However, if global
58
# variables like sys.path are adjusted, this could cause all kinds of
59
# havoc. While this may work, invoking a new process is safer.
60
result = subprocess.call(program, cwd=directory)
63
raise Exception('Error installing package: %s' % directory)
65
# configure invokes us with /path/to/topsrcdir and /path/to/manifest
66
if __name__ == '__main__':
67
assert len(sys.argv) == 3
69
populate_virtualenv(sys.argv[1], sys.argv[2])