justinmayer / virtualfish

Fish shell tool for managing Python virtual environments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`vf connect` should automatically deactivate virtualenvs

zx8 opened this issue · comments

commented

Using virtualfish v2.1.0 with the auto_activation plugin.

When I create a virtualenv and run vf connect, upon leaving that directory, I would expect the virtualenv to automatically be deactivated. However, it's currently necessary to manually run vf deactivate in order to deactivate it.

Would it be possible to change the behaviour such that it is automatically deactivated?

I've never used the auto_activation plugin nor have I touched its code in any meaningful way. That said, I just did some experiments and have some off-the-cuff thoughts.

I get the impression the behavior you described is functioning as intended. The reason the virtual environment is not de-activated automatically in the above scenario is that it was not automatically activated in the first place. I imagine the automatic activation logic must set a variable akin to "hey remember to de-activate when leaving this directory", but when an environment is activated manually, that variable is never set, so the de-activation does not occur when leaving the directory.

If you subsequently leave that directory, manually de-activate, and then go back to that directory, the virtual environment will automatically activate. If you leave, it will automatically de-activate.

I think there is a certain simplicity in the concept that manually-activated environments must be manually de-activated. It seems messy — and potentially rife with unintended side effects — to muddy those waters. But that's just my two cents.

commented

Fair enough, but to provide another point of view (and as a long-time user of the auto_activation plugin): I can safely say that in the last 2-3 years of using it, I have always opted to manually deactivate a virtualenv that I have just run vf connect on upon leaving the directory – it's the sole reason I use vf connect to begin with, after all.

Perhaps my usage is different to the average virtualenv user though...

Another reason I was conflicted about this was that I didn't want to put auto_activation-related code into virtual.fish core, but I realized I could add a new virtualenv_did_connect event and listen for that within the plugin.

I just pushed PR #164, which I think should deliver the behavior you described. Could you give it a try and see whether it does the trick for you?

works for me on virtualfish 2.1.0. I had to do a vf uninstall ; vf install auto_activation $other_plugins for it to work though.

@XenGi: Yeah, I need to at least put in a section about how to upgrade VirtualFish. It's on the to-do list.

By the way, I included this feature in VirtualFish 2.2, which I just released. 💫