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.]
This commit is contained in:
rht 2017-05-11 18:59:07 +07:00 committed by Greg Price
parent f0bb11ef40
commit b0e4233d3f
3 changed files with 24 additions and 14 deletions

View File

@ -295,24 +295,18 @@ Make sure you have followed the steps specific for your platform:
For managing Zulip's python dependencies, we recommend using For managing Zulip's python dependencies, we recommend using
[virtualenvs](https://virtualenv.pypa.io/en/stable/). [virtualenvs](https://virtualenv.pypa.io/en/stable/).
You must create two virtualenvs. One for Python 2 and one for Python 3. You must create a Python 3 virtualenv. You must also install appropriate
You must also install appropriate python packages in them. python packages in it.
You should either install the virtualenvs in `/srv`, or put symlinks to You should either install the virtualenv in `/srv`, or put a symlink to it in
them in `/srv`. If you don't do that, some scripts might not work correctly. `/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 You can run `python3 tools/setup/setup_venvs.py`. This script will create a
virtualenvs - /srv/zulip-venv and /srv/zulip-py3-venv. virtualenv `/srv/zulip-py3-venv`.
If you want to do it manually, here are the steps: 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 virtualenv /srv/zulip-py3-venv -p python3 # Create a python3 virtualenv
sudo chown -R `whoami`:`whoami` /srv/zulip-py3-venv sudo chown -R `whoami`:`whoami` /srv/zulip-py3-venv
source /srv/zulip-py3-venv/bin/activate # Activate python3 virtualenv source /srv/zulip-py3-venv/bin/activate # Activate python3 virtualenv

View File

@ -10,6 +10,12 @@ if [ "$EUID" -eq 0 ]; then
exit 1 exit 1
fi fi
if [ -n "$TRAVIS" ]; then
PYTHON=python
else
PYTHON=python3
fi
#Make the script independent of the location from where it is #Make the script independent of the location from where it is
#executed #executed
PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) 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 # PYTHONUNBUFFERED is important to ensure that tracebacks don't get
# lost far above where they should be in the output. # lost far above where they should be in the output.
export PYTHONUNBUFFERED=1 export PYTHONUNBUFFERED=1
python "$PROVISION_PATH" $@ 2>&1 | tee -a "$LOG_PATH" "$PYTHON" "$PROVISION_PATH" $@ 2>&1 | tee -a "$LOG_PATH"
failed=${PIPESTATUS[0]} failed=${PIPESTATUS[0]}
if [ $failed = 1 ]; then if [ $failed = 1 ]; then
@ -36,5 +42,14 @@ if [ $failed = 1 ]; then
echo "* Logs are here: zulip/var/log/provision.log" echo "* Logs are here: zulip/var/log/provision.log"
echo -e "\033[0m" echo -e "\033[0m"
exit 1 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 fi
exit 0 exit 0

View File

@ -9,6 +9,7 @@ if ZULIP_PATH not in sys.path:
sys.path.append(ZULIP_PATH) sys.path.append(ZULIP_PATH)
from scripts.lib.setup_venv import setup_virtualenv from scripts.lib.setup_venv import setup_virtualenv
from scripts.lib.zulip_tools import run
PY2_VENV_PATH = "/srv/zulip-venv" PY2_VENV_PATH = "/srv/zulip-venv"
PY3_VENV_PATH = "/srv/zulip-py3-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, setup_virtualenv(PY3_VENV_PATH, PY3_DEV_REQS_FILE, patch_activate_script=True,
virtualenv_args=['-p', 'python3']) virtualenv_args=['-p', 'python3'])
else: 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, setup_virtualenv(PY3_VENV_PATH, PY3_DEV_REQS_FILE, patch_activate_script=True,
virtualenv_args=['-p', 'python3']) virtualenv_args=['-p', 'python3'])