mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
tools: Reinstall virtualenv if it is broken
Closes https://github.com/espressif/esp-idf/issues/6656
This commit is contained in:
@@ -1348,14 +1348,30 @@ def get_wheels_dir(): # type: () -> Optional[str]
|
|||||||
|
|
||||||
|
|
||||||
def action_install_python_env(args): # type: ignore
|
def action_install_python_env(args): # type: ignore
|
||||||
|
reinstall = args.reinstall
|
||||||
idf_python_env_path, _, virtualenv_python = get_python_env_path()
|
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)
|
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):
|
if is_virtualenv and (not os.path.exists(idf_python_env_path) or reinstall):
|
||||||
fatal('This script was called from a virtual environment, can not create a virtual environment again')
|
fatal('This script was called from a virtual environment, can not create a virtual environment again')
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
if args.reinstall and os.path.exists(idf_python_env_path):
|
if os.path.exists(virtualenv_python):
|
||||||
|
try:
|
||||||
|
subprocess.check_call([virtualenv_python, '--version'], stdout=sys.stdout, stderr=sys.stderr)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
# At this point we can reinstall the virtual environment if it is non-functional. This can happen at least
|
||||||
|
# when the Python interpreter was removed which was used to create the virtual environment.
|
||||||
|
reinstall = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.check_call([virtualenv_python, '-m', 'pip', '--version'], stdout=sys.stdout, stderr=sys.stderr)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
warn('PIP is not available in the virtual environment.')
|
||||||
|
# Reinstallation of the virtual environment could help if PIP was installed for the main Python
|
||||||
|
reinstall = True
|
||||||
|
|
||||||
|
if reinstall and os.path.exists(idf_python_env_path):
|
||||||
warn('Removing the existing Python environment in {}'.format(idf_python_env_path))
|
warn('Removing the existing Python environment in {}'.format(idf_python_env_path))
|
||||||
shutil.rmtree(idf_python_env_path)
|
shutil.rmtree(idf_python_env_path)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user