setup_venv: Link to the correct Python interpreter.

Travis enables different Python versions through virtual environments,
but it seems that there is a little caveat when we try to create Zulip's
virtual environment by referring Travis' virtual environment; Zulip's
virtual environment refers the system Python. We encountered this
behaviour when we tried to run our backend test suite under Python 3.5
in Travis. 'python3 --version' command before activating Zulip's
virtualenv showed 'Python 3.5.3' and after it showed 'Python 3.4.3'.
This happened when we created the virtual environment using
'virtualenv -p python3'.

The solution seems to be to explicitly give the path of the Python
interpreter in the Travis' virtual environment using 'which python3'.
This commit is contained in:
Umair Khan 2017-09-01 09:27:30 +05:00 committed by showell
parent d7f10bf3a1
commit c039f73656
1 changed files with 7 additions and 3 deletions

View File

@ -9,7 +9,7 @@ if ZULIP_PATH not in sys.path:
sys.path.append(ZULIP_PATH)
from scripts.lib.setup_venv import setup_virtualenv
from scripts.lib.zulip_tools import run
from scripts.lib.zulip_tools import run, subprocess_text_output
OLD_VENV_PATH = "/srv/zulip-venv"
VENV_PATH = "/srv/zulip-py3-venv"
@ -18,13 +18,17 @@ DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "dev_lock.txt")
def main(is_travis=False):
# type: (bool) -> None
# Get the correct Python interpreter. If we don't do this and use
# `virtualenv -p python3` to create the venv in Travis, the venv
# starts referring to the system Python interpreter.
python_interpreter = subprocess_text_output(['which', 'python3'])
if is_travis:
setup_virtualenv(VENV_PATH, DEV_REQS_FILE, patch_activate_script=True,
virtualenv_args=['-p', 'python3'])
virtualenv_args=['-p', python_interpreter])
else:
run(['sudo', 'rm', '-f', OLD_VENV_PATH])
setup_virtualenv(VENV_PATH, DEV_REQS_FILE, patch_activate_script=True,
virtualenv_args=['-p', 'python3'])
virtualenv_args=['-p', python_interpreter])
if __name__ == "__main__":
main()