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

Don't auto-deactivate venv if it's not a project #210

Merged
merged 1 commit into from Sep 5, 2021

Conversation

cecep2
Copy link
Contributor

@cecep2 cecep2 commented Jun 29, 2021

Uff, I just realized that #209 introduced a rather unfortunate bug: when I just want to activate a venv that is not connected to any project or has an activation file ( vf activate testvenv), #209 will immediately deactivate the venv when changing the directory (because it's not in $PROJECT_HOME). To fix this, I now also check if $VIRTUAL_ENV is in vf lsprojects

Check if $VIRTUAL_ENV is in vf lsprojects before deactivating.

Moreover, the check:

`not set -q VF_AUTO_ACTIVATED project_path`

Doesn't seem to work as expected. Now these variables are checked
separately.
@cecep2
Copy link
Contributor Author

cecep2 commented Jun 30, 2021

One detail to add: This is still an imperfect solution. If I connect my project in $PROJECT_HOME to a virtualenv using an activation file, the virtualenv of this project might not be auto-deactivated IF I activated it with vf workon project. This is because:

a) switching into project directories with vf workon project doesn't set the VF_AUTO_ACTIVATED flag, that only happens when the cd command is used
b) the virtualenv specified in the activation file might not have a corresponding directory in $PROJECT_HOME and with this patch we only auto-deactivate if $VIRTUAL_ENV is in vf lsprojects

I think a more complete solution would require changes to the projects plugin where we could set something like a PROJECT_ACTIVATED flag that would be checked in the auto-activation plugin, but I remember that a similar proposal was rejected earlier because it's problematic from a "principle of least astonishment" perspective. However, for me personally the solution here is 'good enough' since I don't use activation files for projects stored in $PROJECT_HOME.

@justinmayer
Copy link
Owner

@cecep2: Many thanks for the fix. I don't recall the previous discussion, but I'm not opposed to us divining a more elegant solution at some point down the road.

@justinmayer justinmayer merged commit 53f08f9 into justinmayer:main Sep 5, 2021
@cecep2 cecep2 deleted the autodeactivate_projecthome branch September 15, 2021 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants