pyenv-virtualenv icon indicating copy to clipboard operation
pyenv-virtualenv copied to clipboard

virtualenv-delete -f can exit with non-zero return code

Open KevOrr opened this issue 5 years ago • 4 comments

$ pyenv virtualenv-delete --help
Usage: pyenv virtualenv-delete [-f|--force] <virtualenv>

   -f  Attempt to remove the specified virtualenv without prompting
       for confirmation. If the virtualenv does not exist, do not
       display an error message.

See `pyenv virtualenvs` for a complete list of installed versions.

yet

$ pyenv virtualenv-delete -f nonexistant
pyenv-virtualenv: `nonexistant' is not a virtualenv.
$ echo $?
1

Currently, 2 ENOENT-ish error codes can be printed without checking the value of $FORCE. More importantly, the script exits with a non-zero return code, which seems contrary to the spirit of -f.

https://github.com/pyenv/pyenv-virtualenv/blob/294f64f76b6b7fbf1a22a4ebba7710faa75c21f7/bin/pyenv-virtualenv-delete#L68-L89

KevOrr avatar Oct 21 '20 17:10 KevOrr

I know this issue is extremely old. I had the same issue. You can step around it by executing pyenv uninstall -f nonexistent instead and it will remove the virtual environment.

tamaroth avatar Nov 30 '21 15:11 tamaroth

Hello, same issue here with pyenv 2.3.1-20-g572a8bcf

clotildeguinard avatar Jun 28 '22 10:06 clotildeguinard

I know this issue is extremely old. I had the same issue. You can step around it by executing pyenv uninstall -f nonexistent instead and it will remove the virtual environment.

@tamaroth I have found your work around doesn't work. Let's say I have a virtual env foo:

$ pyenv versions
  system
* 3.9.12 (set by /home/foobar/.pyenv/version)
  3.9.12/envs/foo
  foo

Then I:

$ pyenv uninstall -f 3.9.12/envs/foo
pyenv: foo uninstalled

But now:

$ pyenv versions
  system
* 3.9.12 (set by /home/foobar/.pyenv/version)
  3.9.12/envs/foo

It didn't actually delete foo, just the extra name for the real venv. Still the same outcome if I use the short name, foo:

$ pyenv uninstall -f foo
pyenv: foo uninstalled
$ pyenv versions
  system
* 3.9.12 (set by /home/foobar/.pyenv/version)
  3.9.12/envs/foo

jtnz avatar Sep 23 '22 00:09 jtnz

Ohh, I've found if you use the full venv name with virtualenv-delete it works:

$ pyenv virtualenv-delete --force 3.9.12/envs/foo

Doesn't matter if it doesn't exist either, it's always silent, always 0 return code.

jtnz avatar Sep 23 '22 00:09 jtnz

Can't reproduce now.

native-api avatar Jan 31 '23 20:01 native-api