MichaelAquilina / zsh-autoswitch-virtualenv

🐍 ZSH plugin to automatically switch python virtualenvs (including pipenv and poetry) as you move between directories
GNU General Public License v3.0
507 stars 80 forks source link

Fix switching from venv to venv #203

Open NeilGirdhar opened 3 weeks ago

NeilGirdhar commented 3 weeks ago
❯ cd tjax
Switching virtualenv: .venv [🐍Python 3.12.3]
❯ cd ../efax
Switching virtualenv: .venv [🐍Python 3.12.4]
❯ cd efax/_src
❯ 

Without this change, venv-name is '.venv' for both directories.

MichaelAquilina commented 3 weeks ago

@NeilGirdhar not sure I follow the issue. Would you mind elaborating a bit more? I'm wondering what test case we can add to prevent regressions

NeilGirdhar commented 3 weeks ago

@MichaelAquilina Thanks for taking a look!

The problem occurs when you switch directly from one venv to another. Normally, this tool won't deactivate the old environment and activate the new one (at least for me). So, I would have to do:

❯ cd tjax
Switching virtualenv: .venv [🐍Python 3.12.3]
❯ cd ..
Deactivating: .venv
❯ cd efax
Switching virtualenv: .venv [🐍Python 3.12.4]
❯ 

If I try to go directly, it does:

❯ cd tjax
Switching virtualenv: .venv [🐍Python 3.12.3]
❯ cd ../efax
❯ 

It doesn't switch.

MichaelAquilina commented 2 weeks ago

ah I think now I get what you're saying - if the virtualenv name is the same (in this case .venv, the reactivation does not happen?

Could I ask how you got those virtual environments setup in the first place so that I can reproduce a scenario and write tests for it?

NeilGirdhar commented 2 weeks ago

ah I think now I get what you're saying - if the virtualenv name is the same (in this case .venv, the reactivation does not happen?

Exactly!

Could I ask how you got those virtual environments setup in the first place so that I can reproduce a scenario and write tests for it?

A virtual environment for a Python project will get the name .venv if it's set up by uv sync or poetry install with [virtualenvs] in-project = true.