From 4f181acb83e7b01b5c11fbb1a03a843098e7ddf8 Mon Sep 17 00:00:00 2001 From: Eklavya Sharma Date: Sun, 3 Jul 2016 01:45:55 +0530 Subject: [PATCH] Add python 3 mode to provision.py. When provision.py is run using python 2, retain original behavior of creating a python 2 venv using requirements/py2_dev.txt and creating a python 3 venv using requirements/mypy.txt. When provision.py is run using python 3, install a single python 3 venv with requirements/py3_dev.txt. --- tools/provision.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/provision.py b/tools/provision.py index 442e913958..951bff8bc8 100755 --- a/tools/provision.py +++ b/tools/provision.py @@ -8,6 +8,8 @@ import subprocess os.environ["PYTHONUNBUFFERED"] = "y" +PY2 = sys.version_info[0] == 2 + ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(ZULIP_PATH) @@ -22,10 +24,15 @@ SUPPORTED_PLATFORMS = { } NPM_VERSION = '3.9.3' -VENV_PATH = "/srv/zulip-venv" +PY2_VENV_PATH = "/srv/zulip-venv" PY3_VENV_PATH = "/srv/zulip-py3-venv" TRAVIS_NODE_PATH = os.path.join(os.environ['HOME'], 'node') +if PY2: + VENV_PATH = PY2_VENV_PATH +else: + VENV_PATH = PY3_VENV_PATH + if not os.path.exists(os.path.join(ZULIP_PATH, ".git")): print("Error: No Zulip git repository present!") print("To setup the Zulip development environment, you should clone the code") @@ -150,10 +157,14 @@ def main(): run(["wget", "-O", temp_deb_path, TSEARCH_URL]) run(["sudo", "dpkg", "--install", temp_deb_path]) - setup_virtualenv(PY3_VENV_PATH, - os.path.join(ZULIP_PATH, "requirements", "mypy.txt"), - virtualenv_args=['-p', 'python3']) - setup_virtualenv(VENV_PATH, os.path.join(ZULIP_PATH, "requirements", "py2_dev.txt")) + if PY2: + MYPY_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "mypy.txt") + setup_virtualenv(PY3_VENV_PATH, MYPY_REQS_FILE, virtualenv_args=['-p', 'python3']) + DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py2_dev.txt") + setup_virtualenv(PY2_VENV_PATH, DEV_REQS_FILE) + else: + DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py3_dev.txt") + setup_virtualenv(VENV_PATH, DEV_REQS_FILE, virtualenv_args=['-p', 'python3']) # Put Python2 virtualenv activation in our .bash_profile. with open(os.path.expanduser('~/.bash_profile'), 'w+') as bash_profile: