File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -158,9 +158,25 @@ def _create_virtualenv(self) -> None:
158158 # Late import to avoid circular import errors
159159 from ptscripts .__main__ import CWD
160160
161- if self .venv_dir .exists ():
162- self .ctx .debug ("Virtual environment path already exists" )
163- return
161+ if self .venv_dir .exists () and self .venv_python .exists ():
162+ if not self .venv_python .exists ():
163+ try :
164+ relative_venv_path = self .venv_dir .relative_to (CWD )
165+ except ValueError :
166+ relative_venv_path = self .venv_dir
167+ try :
168+ relative_venv_python_path = self .venv_python .relative_to (CWD )
169+ except ValueError :
170+ relative_venv_python_path = self .venv_python
171+ self .ctx .warn (
172+ f"The virtual environment path '{ relative_venv_path } ' exists but the "
173+ f"python binary '{ relative_venv_python_path } ' does not. Deleting the "
174+ "virtual environment."
175+ )
176+ shutil .rmtree (self .venv_dir )
177+ else :
178+ self .ctx .debug ("Virtual environment path already exists" )
179+ return
164180 virtualenv = shutil .which ("virtualenv" )
165181 if virtualenv :
166182 cmd = [
You can’t perform that action at this time.
0 commit comments