pdm-project / pdm

A modern Python package and dependency manager supporting the latest PEP standards
https://pdm-project.org
MIT License
7.91k stars 395 forks source link

Suppressing errors with `pdm venv remove` #3138

Closed BVMiko closed 1 month ago

BVMiko commented 1 month ago

Is your feature/enhancement proposal related to a problem? Please describe.

I submitted #3137 while looking into this, but that was only a side issue.

What I'm hoping for is a command which can be run from a script, and will delete the ./.venv/ folder if present and also remove the ./.pdm-python file if applicable. This is going to go into a Makefile's make clean script, so I hope for it to return a zero (success) exit status even if there is no existing ./.venv/ folder.

The src/pdm/cli/commands/venv/utils.py file has two distinct iterators (iter_venvs used by pdm venv remove and iter_central_venvs used by pdm venv purge). The existence of the separate iterator makes it look as though the pdm venv purge is intended to exclude in-project venvs. So, it seems like pdm venv remove would be the correct target for this change.

Describe the solution you'd like

I would like to add a new argument to the pdm venv remove command (perhaps -i|--ignore or -s|--suppress?) which will suppress the PdmUsageError, and return a success exit status if there is no matching venv.

frostming commented 1 month ago

Why not pdm venv remove || true?

BVMiko commented 1 month ago

That's the route that I ended up taking shortly after posting this. It makes sense to not add another argument for use with shell scripts when it's easy enough to do with shell code.