Closed petobens closed 1 month ago
Thanks for the visual explaination!
Its also good since im not using Poetry myself, but I would like to make this work with the plugin. Let me experiment a bit with this and see if I can come up with something...
I was thinking about this one again now. I think this is an issue with how shells work.
If you update the PATH environment variable from one shell (this is basically what VenvSelect
does when it activates a venv) you will only see that change in new shells launched from neovim itself.
New shells would have that PATH environment variable changed, but not all shells on your system. This would explain why your shell at the bottom of the screen doesnt know about what you changed within VenvSelect. But if you would launch a new shell from inside neovim, it should have the new env first in the PATH.
Understand what i mean?
Hey, since this issue is still open, I didn't want to create another one. I have the same problem. As shown in the gif, .venv has numpy installed and .venv1 does not. If this plugin aims only to correct the LSP, then it's fine. However, inside the terminal, when running the code, I still need to source it manually. Idk if it's related but i open the terminal inside neovim via toggleterm
This is because of how terminals work in linux. Any terminal that was running before you activated the venv will not get the new venv activated. But if you open a new terminal after you have activated a venv with the plugin, the new terminal should have it activated.
Toggleterm probably reuses the same terminal all the time and just hides it, which would explain the issue here. :)
You can try to just run :term
inside neovim after you activate a venv. And if you type echo $PATH
, you should see the activated venv first in the PATH. And the VIRTUAL_ENV
env variable should be set also.
I see. I tried and yes it's working as expected. Thanks for the clarification.
Ok great. But thank you very much for writing this issue. I'm working on a rewrite of the plugin in the regexp branch right now, and I will add a hook so people can run any command after a venv has been activated, such as the "poetry env use" command.
The rewrite is much better designed for supporting any venv since users can write their own search commands with fd and find whatever they want.
I added a callback function for when an env is activated and wrote an example in the README how you can make VenvSelect
run poetry env use <selected python>
when you open a terminal. I think its a good usecase to show how that function allows a lot of flexibility.
This is all in the regexp
branch and here is the example: https://github.com/linux-cultist/venv-selector.nvim/tree/regexp?tab=readme-ov-file#run-your-own-code-on-venv-activation-on_venv_activate_callback
Please let me know if this solution works for you. It was over a year since this issue was created, but I always liked the idea and wanted to implement it in a generic way that works for more than just poetry
.
Great thanks!
I'll close this issue then but you can still comment on it if you have suggestions how to improve this feature. :)
In my GIF I have two environments with poetry, one with python 3.10 and another one with 3.11. If I then
poetry env list
from a terminal I see that the currently activated venv is 3.10.:VenvSelect
and choose the 3.11 environmentpoetry env list
-> poetry still sees 3.10 as the active environment.So I guess that what's missing is to run
poetry env use <env>
during activation of an environment.