2016-06-25 17:07:13 +02:00
|
|
|
"""
|
|
|
|
Use libraries from a virtualenv (by modifying sys.path) in production.
|
|
|
|
"""
|
|
|
|
|
2017-09-22 18:30:18 +02:00
|
|
|
import os
|
2016-06-25 17:07:13 +02:00
|
|
|
import sys
|
|
|
|
|
2017-09-22 08:15:01 +02:00
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2019-01-10 01:57:27 +01:00
|
|
|
|
|
|
|
venv = os.path.join(BASE_DIR, "zulip-py3-venv")
|
|
|
|
if sys.prefix != venv:
|
|
|
|
activate_this = os.path.join(venv, "bin", "activate_this.py")
|
2016-06-25 17:07:13 +02:00
|
|
|
# this file will exist in production
|
2019-01-10 01:57:27 +01:00
|
|
|
if os.path.exists(activate_this):
|
|
|
|
activate_locals = dict(__file__=activate_this)
|
|
|
|
exec(open(activate_this).read(), {}, activate_locals)
|
2019-01-10 01:58:50 +01:00
|
|
|
if not os.path.exists(activate_locals["site_packages"]):
|
|
|
|
raise RuntimeError(venv + " was not set up for this Python version")
|