From 5d399b459cd977927645a205b9ecb47fd8a144d5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 26 Feb 2020 14:02:12 +0100 Subject: [PATCH] tools: check if idf_tools.py install-python-env is called from a venv Closes IDF-1095 --- tools/idf_tools.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index bc1c882d2..2ec3b6f16 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -1185,6 +1185,11 @@ def action_install(args): def action_install_python_env(args): idf_python_env_path, _, virtualenv_python = get_python_env_path() + is_virtualenv = hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) + if is_virtualenv and (not os.path.exists(idf_python_env_path) or args.reinstall): + fatal('This script was called from a virtual environment, can not create a virtual environment again') + raise SystemExit(1) + if args.reinstall and os.path.exists(idf_python_env_path): warn('Removing the existing Python environment in {}'.format(idf_python_env_path)) shutil.rmtree(idf_python_env_path)