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

Auto-deactivate venvs in $PROJECT_HOME without requiring .project files #209

Merged
merged 1 commit into from
Jun 28, 2021

Conversation

cecep2
Copy link
Contributor

@cecep2 cecep2 commented Jun 18, 2021

This is an attempt to improve my previous pull request about making the auto-activation plugin 'project aware', so that virtualenvs of projects are automatically deactivated when leaving the project directory (#175). The solution back then was to only deactivate virtualenvs of projects automatically if they contain a .project file. However, this solution feels very unintuitive to me, partly because it seems against the 'intended' use of the projects plugin, which suggests to only use .project files if the project is not in the $PROJECT_HOME directory - and I like to keep all my projects in $PROJECT_HOME.

This patch aims to accommodate this workflow by auto-deactivating virtualenvs of projects in $PROJECT_HOME without needing .project or .venv files. It adds a check to the auto-activation plugin that auto-deactivates venvs if all of these conditions are true:

  1. Virtualenv was not auto-activated (by an activation file) and doesn't contain a .project file
  2. $PWD is not a subdirectory of $PROJECT_HOME (because projects are stored as $PROJECT_HOME/project1-dir, $PROJECT_HOME/project2-dir etc.)

By testing for these very specific conditions, this patch should not interfere with the normal usage of .venv and .project files in any way. Implementing this required very few code additions and the interaction between the auto-activation and projects plugin feels more intuitive to me: Now I can continue to use the projects plugin 'as intended' while benefiting from the convenience of the auto-activation plugin.

I've also updated the old comments explaning Projects plugin compatibility to reflect this change.

This is an attempt to improve my previous pull request about making the
auto-activation plugin project aware (justinmayer#175). The solution back then was
to only deactivate virtualenvs of projects automatically if they contain
a .project file. However, this solution feels very unintuitive to me,
partly because it seems against the 'intended' use of the projects
plugin, which suggests to only use .project files if the project is not
in the $PROJECT_HOME directory - and I like to keep all my projects in
$PROJECT_HOME.

This patch aims to accommodate this workflow by auto-deactivating
virtualenvs of projects in $PROJECT_HOME without needing .project or
.venv files. It adds a check to the auto-activation plugin:
auto-deactivate venv if a) it's not auto-activated and doesn't contain a
.project file, AND b) it's not a subdirectory of $PROJECT_HOME. By
testing for these very specific conditions, this patch should not
interfere with the normal usage of .venv and .project files in any way.
@justinmayer
Copy link
Owner

Makes sense to me. Well done! 💫

@justinmayer justinmayer merged commit ae5873e into justinmayer:master Jun 28, 2021
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