xonsh / xontrib-vox

Python virtual environment manager for xonsh.
MIT License
15 stars 3 forks source link

`vox activate` fails when currently active virtualenv is removed #3

Open ghost opened 4 years ago

ghost commented 4 years ago

xonfig

Clean install (inside a temp virtualenv), started as xonsh --no-rc

``` $ xonfig +------------------+----------------------+ | xonsh | 0.9.13.dev1 | | Git SHA | 9f7ccc65 | | Commit Date | Oct 15 17:14:50 2019 | | Python | 3.6.9 | | PLY | 3.11 | | have readline | True | | prompt toolkit | 3.0.3 | | shell type | prompt_toolkit2 | | pygments | 2.5.2 | | on posix | True | | on linux | True | | distro | unknown | | on darwin | False | | on windows | False | | on cygwin | False | | on msys2 | False | | is superuser | False | | default encoding | utf-8 | | xonsh encoding | utf-8 | | encoding errors | surrogateescape | +------------------+----------------------+ ```

Expected Behavior

The old virtualenv should be deactivated and the new virtualenv should be activated

Current Behavior

An error message is shown, old virtualenv is deactivated but new virtualenv isn't activated.

Steps to Reproduce

Open 2 xonsh instances.

In xonsh instance 1:

$  xontrib load vox
$  vox create foo
$  vox create bar
$  vox activate foo

In xonsh instance 2:

$  vox remove foo

or just remove or rename the virtualenv directory directly.

Back in xonsh instance 1:

$  vox activate bar
This environment doesn't exist. Create it with "vox new bar".

Note that a second vox activate bar does succeed (as the foo virtualenv has been deactivated by the first attempt):

$  vox activate bar
Activated "bar".

Additional info

Some quick debugging seems to indicate the problem is due to https://github.com/xonsh/xonsh/blob/master/xontrib/voxapi.py#L288 , the ve.bin dir doesn't exist (obviously, the virtualenv got removed ;) ) so the else: part of the for loop gets triggered, raising a KeyError. This gets caught by the except KeyError: part in cmd_activate() ( https://github.com/xonsh/xonsh/blob/master/xontrib/vox.py#L161 ).

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

AstraLuma commented 4 years ago

That's.... odd.

In my local version, I get this:

🐚 vox create tmp
Creating environment...
Environment 'tmp' created. Activate it with "vox activate tmp".

🐚 vox activate tmp
Activated "tmp".

🐚 vox remove tmp
The "tmp" environment is currently active. In order to remove it, deactivate it first with "vox deactivate tmp".
AstraLuma commented 4 years ago

(Now, if you delete the venv directory out from under vox, I could see things getting funky.)

ghost commented 4 years ago

Yes, that's why you need to have (at least) 2 Xonsh instances running (and do the vox remove ... in a different Xonsh instance then the one where the venv is not active) when using vox for the removal ;)

AstraLuma commented 4 years ago

Ahhh, I see.

Yeah, that'll probably cause problems.