setup_path_on_import: Skip activate_this if already activated.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2019-01-09 16:57:27 -08:00
committed by Tim Abbott
parent 2ad1a27b28
commit 7a58f574bf

View File

@@ -7,12 +7,13 @@ import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
activate_this = os.path.join(
BASE_DIR,
"zulip-py3-venv",
"bin",
"activate_this.py")
if os.path.exists(activate_this):
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
exec(open(activate_this).read(), {}, dict(__file__=activate_this))
if os.path.exists(activate_this):
activate_locals = dict(__file__=activate_this)
exec(open(activate_this).read(), {}, activate_locals)
sys.path.append(BASE_DIR)