aboutsummaryrefslogtreecommitdiffstats
path: root/python/mach_bootstrap.py
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-08-08 19:42:14 -0600
committerbors-servo <metajack+bors@gmail.com>2015-08-08 19:42:14 -0600
commitc315404db80c92a695531b0aa4bcf61c125a3bff (patch)
tree9b543c68e4230741bf907532bc455efe6733990a /python/mach_bootstrap.py
parentb00583bd4e7169a6b952633df718268904f2bd0c (diff)
parentb327e9b595c2d55f499b872a5ffd72835e1f3e24 (diff)
downloadservo-c315404db80c92a695531b0aa4bcf61c125a3bff.tar.gz
servo-c315404db80c92a695531b0aa4bcf61c125a3bff.zip
Auto merge of #7103 - frewsxcv:python-venv, r=metajack
Use one Python virtual environment for all mach commands *See individual commits for more information* <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7103) <!-- Reviewable:end -->
Diffstat (limited to 'python/mach_bootstrap.py')
-rw-r--r--python/mach_bootstrap.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/python/mach_bootstrap.py b/python/mach_bootstrap.py
index 84de5b22b25..e04d1781bdd 100644
--- a/python/mach_bootstrap.py
+++ b/python/mach_bootstrap.py
@@ -6,7 +6,9 @@ from __future__ import print_function, unicode_literals
import os
import platform
+import subprocess
import sys
+from distutils.spawn import find_executable
SEARCH_PATHS = [
"python/mach",
@@ -73,6 +75,39 @@ CATEGORIES = {
}
+def _get_exec(name, default=None):
+ path = find_executable(name)
+ if not path:
+ return default
+ return path
+
+
+def _activate_virtualenv(topdir):
+ virtualenv_path = os.path.join(topdir, "python", "_virtualenv")
+ python = _get_exec("python2", "python")
+
+ if not os.path.exists(virtualenv_path):
+ virtualenv = _get_exec("virtualenv2", "virtualenv")
+ subprocess.check_call([virtualenv, "-p", python, virtualenv_path])
+
+ activate_path = os.path.join(virtualenv_path, "bin", "activate_this.py")
+ execfile(activate_path, dict(__file__=activate_path))
+
+ # TODO: Right now, we iteratively install all the requirements by invoking
+ # `pip install` each time. If it were the case that there were conflicting
+ # requirements, we wouldn't know about them. Once
+ # https://github.com/pypa/pip/issues/988 is addressed, then we can just
+ # chain each of the requirements files into the same `pip install` call
+ # and it will check for conflicts.
+ requirements_paths = [
+ os.path.join(topdir, "python", "requirements.txt"),
+ os.path.join(topdir, "tests", "wpt", "harness", "requirements.txt"),
+ os.path.join(topdir, "tests", "wpt", "harness", "requirements_servo.txt"),
+ ]
+ for path in requirements_paths:
+ subprocess.check_call(["pip", "install", "-q", "-r", path])
+
+
def bootstrap(topdir):
topdir = os.path.abspath(topdir)
@@ -84,6 +119,8 @@ def bootstrap(topdir):
print('You are running Python', platform.python_version())
sys.exit(1)
+ _activate_virtualenv(topdir)
+
def populate_context(context, key=None):
if key is None:
return