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

vox activate fails when currently active virtualenv is removed #3

Open
ghost opened this issue Feb 24, 2020 · 4 comments
Open

vox activate fails when currently active virtualenv is removed #3

ghost opened this issue Feb 24, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Feb 24, 2020

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
Copy link
Member

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
Copy link
Member

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

@ghost
Copy link

ghost commented Feb 24, 2020

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
Copy link
Member

Ahhh, I see.

Yeah, that'll probably cause problems.

@anki-code anki-code added the bug Something isn't working label Feb 14, 2021
@anki-code anki-code transferred this issue from xonsh/xonsh Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants