pypa / virtualenv

Virtual Python Environment builder
https://virtualenv.pypa.io
MIT License
4.78k stars 1.02k forks source link

Keep PWD when deactivating `venv` on nushell (activate.nu) #2745

Closed dmatos2012 closed 2 months ago

dmatos2012 commented 2 months ago

What's the problem this feature will solve? deactivateing venv will not change the PWD back to where it was activated

Problem:

mkdir v1 && cd v1
virtualenv venv
overlay use venv/bin/activate.nu

mkdir v2 && cd v2
virtualenv venv
pwd
# v2

Then I remember I had the venv from v1 directory activated, and I do

deactivate

Unexpected behavior: cwd changes to v1

Expected behavior: I would like to stay in v2

Describe the solution you'd like

Stay in the current directory

How to solve?

Currently , the activate.nu, has the alias to deactivate, which can be changed to:

overlay hide --keep-env [ PWD ] activate

In that way, cwd stays in v2 rather than v1.

Alternative Solutions

Additional context I like to name all my venvs venv becauwe its easy, but i work with multiple a day, so I am constantly switching between them, and I forget to deactivate it, and thus im constantly having to change back to the cwd.

Tbh, I dont know if this will break for other people so not sure if it needs to be a config or what, but yeah wanted to raise an issue first to see if this is a problem for others, and then maybe add the one liner PR.

gaborbernat commented 2 months ago

We don't do per shell customization, it's all or nothing.

For a change this impactful you'd need CPython venv but in first, so create an issue there.

pfmoore commented 2 months ago

CPython's venv doesn't have a nushell activation script, so this is a virtualenv-only feature. But the activation scripts implemented in venv leave the CWD unchanged when deactivating, so I think it makes sense that the nushell script should work the same way.