Merge branch 'bugfix/idf_tools_check_virtualenv' into 'master'

tools: check if idf_tools.py install-python-env is called from a venv

Closes IDF-1095

See merge request espressif/esp-idf!7793
This commit is contained in:
Ivan Grokhotkov 2020-03-07 18:07:41 +08:00
commit f7d1ed5f32

View file

@ -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)