Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove _saved_python when purging venv #3137

Merged
merged 3 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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

Check warning on line 66 in src/pdm/cli/commands/venv/purge.py

View check run for this annotation

Codecov / codecov/patch

src/pdm/cli/commands/venv/purge.py#L66

Added line #L66 was not covered by tests
project.core.ui.echo("Purged successfully!")
Loading