-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Make the auto activation and projects plugin play nice together #175
Conversation
This patch ensures that that the auto activation and projects plugin play nice together: - Activating a venv and switching directory using `vf workon` now sets VF_AUTO_ACTIVATED flag if auto activation plugin is sourced - In the auto activation plugin, check if projects plugin is sourced. If so, check if PWD is a project directory to make sure changing into project subdirectories does not deactivate venv
Explain that using both auto-activation and projects means that the virtual environment of the project will be deactivated automatically when leaving the project directory.
I think I misunderstood your comment that inspired this PR. I did not realize that you are looking for auto-deactivation to occur even when no auto-activation occurred. From a "principle of least astonishment" perspective, I am not entirely certain that is sensible default behavior for folks who use both of these plugins. Regarding implementation... I realize that it's hard to keep plugin functionality separate when folks want to use multiple plugins together, but these changes are a bit more involved / inter-twined than I think independent plugins should perhaps be. Moreover, the As far as implementation, I think perhaps one of the simplest solutions would be to add three lines to the virtualfish/virtualfish/projects.fish Lines 131 to 140 in 66019c9
That does the trick in my testing and works no matter how plugins are loaded, albeit only for So... I'm not yet sure whether it's best to do this at all, and if so, in what way. I fully understand you invested time in this endeavor, and I want to respect that while simultaneously ensuring the long-term maintainability of the code. 😅 I thought I'd at least write down my initial impressions so we can discuss further. |
Thanks for the feedback - I'm not a programmer by training, so this is helpful :-) I think at least in cases where there is an activation file in the project dir, auto-activation should be triggered so that the venv is auto-deactivated when leaving. Currently, when I use My personal preference would be to make the auto-activation plugin fully project aware without touching the projects plugin at all, would this still be too inter-twined? |
That sounds reasonable enough to me; I agree that this logic would best located in the auto-activation plugin. If at some point in the future some folks find this behavior change undesirable, I suppose down the road we could consider adding a preference setting.
That certainly is the simplest solution and doesn't seem like a significant burden to me. But I understand if you would still like to implement a solution that skips that step. |
Taking back changes to the Projects plugin, but expanding the Auto-activation plugin to better detect projects in three steps: 1. Check if currently active virtualenv is connected to a project and save its path 2. For cases where no activation file exists in the project directory, additionally check if activation root is in project path to set new_virtualenv_name 3. Finally, additionally check if any virtualenv is active while project path doesn't match activation root. If so, auto-deactivate virtualenv
Now the Projects plugin remains untouched, everything happens in the Auto activation plugin. I don't check if the Projects plugin is sourced and just check if a $VIRTUAL_ENV/.project file exists instead. I think it's reasonable to assume that users having such a file in their virtualenv use the Projects plugin, and this way it doesn't matter in which order these plugins are sourced. |
While there are Projects plugin use cases that don't involve Many thanks for your continued work on this endeavor! 💫 |
Thanks for merging! I admit I totally forgot to take into account that creating a new project doesn't automatically add a |
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.
The goal of this PR is to ensure that projects activated with
vf workon
are deactivated again when leaving the project's directory in cases where both the projects and the auto-activation plugins are used.vf workon
now sets VF_AUTO_ACTIVATED flag if auto activation plugin is sourcedI'm not exactly an expert in Fish and wasn't sure what's the best way to check if another plugin has been sourced. I just check if a particular function from the projects or auto-activation plugin is available using
type -q
, but please advice if there is a better way to do this