From 9233b3bc75faddbfca7ca8c72de4e37b44c83b60 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 7 Feb 2019 04:52:12 -0800 Subject: [PATCH] setup_path_on_import: Always make sure zulip-py3-venv is activated. Signed-off-by: Anders Kaseorg --- scripts/lib/setup_path_on_import.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scripts/lib/setup_path_on_import.py b/scripts/lib/setup_path_on_import.py index f38d44e5e1..d15ca2a2df 100644 --- a/scripts/lib/setup_path_on_import.py +++ b/scripts/lib/setup_path_on_import.py @@ -5,14 +5,11 @@ Use libraries from a virtualenv (by modifying sys.path) in production. 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: +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") - # 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") + 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")