From 6548f1dd1c5e71e85bdc72d289877a63720106b3 Mon Sep 17 00:00:00 2001 From: Eklavya Sharma Date: Wed, 20 Jul 2016 19:56:50 -0400 Subject: [PATCH] Factor out venv-installing code into a module. Factor out the code in tools/provision.py which installs a python2 and python3 venv into a module (tools/setup/setup_venvs.py) which can also be used as a script. --- docs/install-generic-unix-dev.md | 2 +- tools/provision.py | 8 ++++---- tools/setup/setup_venvs.py | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100755 tools/setup/setup_venvs.py diff --git a/docs/install-generic-unix-dev.md b/docs/install-generic-unix-dev.md index ef7e4db079..881a7be840 100644 --- a/docs/install-generic-unix-dev.md +++ b/docs/install-generic-unix-dev.md @@ -239,7 +239,7 @@ You must also install appropriate python packages in them. You should either install the virtualenvs in `/srv`, or put symlinks to them in `/srv`. If you don't do that, some scripts might not work correctly. -You can run `tools/setup/setup-venv` to do this. This script will create two +You can run `tools/setup/setup_venvs.py` to do this. This script will create two virtualenvs - /srv/zulip-venv and /srv/zulip-py3-venv. If you want to do it manually, here are the steps: diff --git a/tools/provision.py b/tools/provision.py index 4c13c032f0..b97caeb3f6 100755 --- a/tools/provision.py +++ b/tools/provision.py @@ -178,10 +178,10 @@ def main(): DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py3_dev.txt") setup_virtualenv(VENV_PATH, DEV_REQS_FILE, virtualenv_args=['-p', 'python3']) else: - DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py2_dev.txt") - setup_virtualenv(PY2_VENV_PATH, DEV_REQS_FILE) - DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py3_dev.txt") - setup_virtualenv(PY3_VENV_PATH, DEV_REQS_FILE, virtualenv_args=['-p', 'python3']) + # Import tools/setup_venv.py instead of running it so that we get an + # activated virtualenv for the rest of the provisioning process. + from tools.setup import setup_venvs + setup_venvs.main() # Put Python2 virtualenv activation in our .bash_profile. with open(os.path.expanduser('~/.bash_profile'), 'w+') as bash_profile: diff --git a/tools/setup/setup_venvs.py b/tools/setup/setup_venvs.py new file mode 100755 index 0000000000..9f133f9798 --- /dev/null +++ b/tools/setup/setup_venvs.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import os +import sys +from os.path import dirname, abspath + +ZULIP_PATH = dirname(dirname(dirname(abspath(__file__)))) +if ZULIP_PATH not in sys.path: + sys.path.append(ZULIP_PATH) + +from scripts.lib.setup_venv import setup_virtualenv + +def main(): + # type: () -> None + PY2_DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py2_dev.txt") + setup_virtualenv("/srv/zulip-venv", PY2_DEV_REQS_FILE) + + PY3_DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py3_dev.txt") + setup_virtualenv("/srv/zulip-py3-venv", PY3_DEV_REQS_FILE, virtualenv_args=['-p', 'python3']) + +if __name__ == "__main__": + main()