2020-01-08 00:06:39 +01:00
|
|
|
"""
|
|
|
|
Use libraries from a virtualenv (by modifying sys.path) in production.
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-01-08 00:06:39 +01:00
|
|
|
def setup_path() -> None:
|
|
|
|
if os.path.basename(sys.prefix) != "zulip-py3-venv":
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
venv = os.path.join(BASE_DIR, "zulip-py3-venv")
|
|
|
|
activate_this = os.path.join(venv, "bin", "activate_this.py")
|
|
|
|
activate_locals = dict(__file__=activate_this)
|
2020-10-24 09:33:54 +02:00
|
|
|
with open(activate_this) as f:
|
2023-01-03 02:18:00 +01:00
|
|
|
exec(f.read(), activate_locals) # noqa: S102
|
2020-03-21 13:52:22 +01:00
|
|
|
# Check that the python version running this function
|
|
|
|
# is same as python version that created the virtualenv.
|
|
|
|
python_version = "python{}.{}".format(*sys.version_info[:2])
|
2021-02-12 08:20:45 +01:00
|
|
|
if not os.path.exists(os.path.join(venv, "lib", python_version)):
|
2020-01-08 00:06:39 +01:00
|
|
|
raise RuntimeError(venv + " was not set up for this Python version")
|