Sfoglia il codice sorgente

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

Closes IDF-1095
Ivan Grokhotkov 5 anni fa
parent
commit
5d399b459c
1 ha cambiato i file con 5 aggiunte e 0 eliminazioni
  1. 5 0
      tools/idf_tools.py

+ 5 - 0
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)