From f83fe9e39b549fe6cd185be5c2e0ca6a9d86617b Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Thu, 1 Sep 2016 16:56:18 +0530 Subject: [PATCH] Ensure that we get python and pip from virtualenv --- python/mach_bootstrap.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python/mach_bootstrap.py b/python/mach_bootstrap.py index d63f66492d56..8a568e95df4b 100644 --- a/python/mach_bootstrap.py +++ b/python/mach_bootstrap.py @@ -77,10 +77,10 @@ } -def _get_exec(*names): +def _get_exec(names, is_valid_path=lambda _path: True): for name in names: path = find_executable(name) - if path is not None: + if path and is_valid_path(path): return path return None @@ -100,14 +100,15 @@ def _get_virtualenv_script_dir(): def _activate_virtualenv(topdir): virtualenv_path = os.path.join(topdir, "python", "_virtualenv") - python = _get_exec(*PYTHON_NAMES) + check_exec_path = lambda path: path.startswith(virtualenv_path) + python = _get_exec(PYTHON_NAMES) if python is None: sys.exit("Python is not installed. Please install it prior to running mach.") script_dir = _get_virtualenv_script_dir() activate_path = os.path.join(virtualenv_path, script_dir, "activate_this.py") if not (os.path.exists(virtualenv_path) and os.path.exists(activate_path)): - virtualenv = _get_exec(*VIRTUALENV_NAMES) + virtualenv = _get_exec(VIRTUALENV_NAMES) if virtualenv is None: sys.exit("Python virtualenv is not installed. Please install it prior to running mach.") @@ -122,8 +123,8 @@ def _activate_virtualenv(topdir): execfile(activate_path, dict(__file__=activate_path)) - python = find_executable("python") - if python is None or not python.startswith(virtualenv_path): + python = _get_exec(PYTHON_NAMES, is_valid_path=check_exec_path) + if python is None: sys.exit("Python virtualenv failed to activate.") # TODO: Right now, we iteratively install all the requirements by invoking @@ -148,7 +149,7 @@ def _activate_virtualenv(topdir): except OSError: pass - pip = _get_exec(*PIP_NAMES) + pip = _get_exec(PIP_NAMES, is_valid_path=check_exec_path) if pip is None: sys.exit("Python pip is not installed. Please install it prior to running mach.")