Skip to content

Commit

Permalink
fix: remove _saved_python when purging venv (#3137)
Browse files Browse the repository at this point in the history
* fix: remove _saved_python when purging venv

* fix: Add missing dependency

* Add news fragment
  • Loading branch information
BVMiko authored Sep 1, 2024
1 parent 7cb963d commit e80a81c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/3137.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When running `pdm venv purge`, if the current project's python version had been referencing the removed venv then clear it out.
4 changes: 4 additions & 0 deletions src/pdm/cli/commands/venv/purge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import shutil
from pathlib import Path

from pdm import termui
from pdm.cli.commands.base import BaseCommand
Expand Down Expand Up @@ -58,6 +59,9 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
project.core.ui.echo("Purged successfully!")

def del_all_venvs(self, project: Project) -> None:
saved_python = project._saved_python
for _, venv in iter_central_venvs(project):
shutil.rmtree(venv)
if saved_python and Path(saved_python).parent.parent == venv:
project._saved_python = None
project.core.ui.echo("Purged successfully!")

0 comments on commit e80a81c

Please sign in to comment.