Files
zulip/scripts/lib/setup_path_on_import.py
Anders Kaseorg b9f7b08af2 setup_path_on_import: Check that the virtualenv is compatible.
The site_packages variable points to (e.g.)
zulip-py3-venv/lib/python3.4/site-packages.  If that doesn’t exist,
we’re probably running the wrong Python version.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-01-09 17:32:09 -08:00

22 lines
741 B
Python

"""
Use libraries from a virtualenv (by modifying sys.path) in production.
Also add Zulip's root directory to sys.path
"""
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
venv = os.path.join(BASE_DIR, "zulip-py3-venv")
if sys.prefix != venv:
activate_this = os.path.join(venv, "bin", "activate_this.py")
# this file will exist in production
if os.path.exists(activate_this):
activate_locals = dict(__file__=activate_this)
exec(open(activate_this).read(), {}, activate_locals)
if not os.path.exists(activate_locals["site_packages"]):
raise RuntimeError(venv + " was not set up for this Python version")
sys.path.append(BASE_DIR)