From b0e4233d3fa54782535e30a59a4d0b9b7a64a5c4 Mon Sep 17 00:00:00 2001 From: rht Date: Thu, 11 May 2017 18:59:07 +0700 Subject: [PATCH] Dev environment setup: default to Python 3. From the line in tools/provision it should trickle to the rest of the scripts. This works since almost all the python scripts have been linted to be generic. Proof that the setup is python3 only: with this commit, within the vagrant container env, /srv/zulip-venv is no longer present and `./tools/run-dev.py` runs just fine. [gnprice: Added `rm -f` and warning message, and made small edits.] --- docs/dev-setup-non-vagrant.md | 18 ++++++------------ tools/provision | 17 ++++++++++++++++- tools/setup/setup_venvs.py | 3 ++- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/docs/dev-setup-non-vagrant.md b/docs/dev-setup-non-vagrant.md index 97bee45c1d..a88ff7bbfb 100644 --- a/docs/dev-setup-non-vagrant.md +++ b/docs/dev-setup-non-vagrant.md @@ -295,24 +295,18 @@ Make sure you have followed the steps specific for your platform: For managing Zulip's python dependencies, we recommend using [virtualenvs](https://virtualenv.pypa.io/en/stable/). -You must create two virtualenvs. One for Python 2 and one for Python 3. -You must also install appropriate python packages in them. +You must create a Python 3 virtualenv. You must also install appropriate +python packages in it. -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 should either install the virtualenv in `/srv`, or put a symlink to it in +`/srv`. If you don't do that, some scripts might not work correctly. -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. +You can run `python3 tools/setup/setup_venvs.py`. This script will create a +virtualenv `/srv/zulip-py3-venv`. If you want to do it manually, here are the steps: ``` -sudo virtualenv /srv/zulip-venv -p python2 # Create a python2 virtualenv -sudo chown -R `whoami`:`whoami` /srv/zulip-venv -source /srv/zulip-venv/bin/activate # Activate python2 virtualenv -pip install --upgrade pip # upgrade pip itself because older versions have known issues -pip install --no-deps -r requirements/py2_dev.txt # install python packages required for development - sudo virtualenv /srv/zulip-py3-venv -p python3 # Create a python3 virtualenv sudo chown -R `whoami`:`whoami` /srv/zulip-py3-venv source /srv/zulip-py3-venv/bin/activate # Activate python3 virtualenv diff --git a/tools/provision b/tools/provision index c143714b54..0a79d0c439 100755 --- a/tools/provision +++ b/tools/provision @@ -10,6 +10,12 @@ if [ "$EUID" -eq 0 ]; then exit 1 fi +if [ -n "$TRAVIS" ]; then + PYTHON=python +else + PYTHON=python3 +fi + #Make the script independent of the location from where it is #executed PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) @@ -23,7 +29,7 @@ echo "PROVISIONING STARTING." >> $LOG_PATH # PYTHONUNBUFFERED is important to ensure that tracebacks don't get # lost far above where they should be in the output. export PYTHONUNBUFFERED=1 -python "$PROVISION_PATH" $@ 2>&1 | tee -a "$LOG_PATH" +"$PYTHON" "$PROVISION_PATH" $@ 2>&1 | tee -a "$LOG_PATH" failed=${PIPESTATUS[0]} if [ $failed = 1 ]; then @@ -36,5 +42,14 @@ if [ $failed = 1 ]; then echo "* Logs are here: zulip/var/log/provision.log" echo -e "\033[0m" exit 1 +elif [ "$VIRTUAL_ENV" != "/srv/zulip-py3-venv" ] && [ -z "$TRAVIS" ]; then + echo -e "\033[0;31m" + echo "WARNING: This shell does not have the Python 3 virtualenv activated." + echo "Zulip commands will fail." + echo + echo "To update the shell, run:" + echo " source /srv/zulip-py3-venv/bin/activate" + echo "or just close this shell and start a new one." + echo -en "\033[0m" fi exit 0 diff --git a/tools/setup/setup_venvs.py b/tools/setup/setup_venvs.py index b8828f03af..d6d17cbcd6 100755 --- a/tools/setup/setup_venvs.py +++ b/tools/setup/setup_venvs.py @@ -9,6 +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 PY2_VENV_PATH = "/srv/zulip-venv" PY3_VENV_PATH = "/srv/zulip-py3-venv" @@ -30,7 +31,7 @@ def main(is_travis=False): setup_virtualenv(PY3_VENV_PATH, PY3_DEV_REQS_FILE, patch_activate_script=True, virtualenv_args=['-p', 'python3']) else: - setup_virtualenv(PY2_VENV_PATH, PY2_DEV_REQS_FILE, patch_activate_script=True) + run(['sudo', 'rm', '-f', PY2_VENV_PATH]) setup_virtualenv(PY3_VENV_PATH, PY3_DEV_REQS_FILE, patch_activate_script=True, virtualenv_args=['-p', 'python3'])