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

Only check for python on precmd #176

Closed MichaelAquilina closed 8 months ago

MichaelAquilina commented 2 years ago

This allows plugins like pyenv that load python in PATH later to work correctly

Fixes #175

Tests need to be updated but opening this up early to check if this fixes the original Issue author's problem

MichaelAquilina commented 2 years ago

@seakayone would you mind checking if this branch works for you?

seakayone commented 2 years ago

I have checked it out and it is working for me, Resolves #175

Last login: Tue Mar 29 19:25:52 on ttys001
❯ cd /tmp/foo                                                                                             autoswitch_virtualenv/git/fix/175
Switching virtualenv: foo-ktrt [Python 3.8.12]
(foo-ktrt) /tmp/foo❯ rmvenv
Deactivating: foo-ktrt
Removing foo-ktrt...
/tmp/foo❯ mkvenv
Creating foo-lsgt virtualenv
created virtual environment CPython3.8.12.final.0-64 in 207ms
  creator CPython3Posix(dest=/Users/kleinboelting/.virtualenvs/foo-lsgt, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/kleinboelting/Library/Application Support/virtualenv)
    added seed packages: pip==22.0.4, setuptools==60.9.3, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
Switching virtualenv: foo-lsgt [Python 3.8.12]
(foo-lsgt) /tmp/foo❯
richardh538 commented 2 years ago

~/.oh-my-zsh/custom/plugins on  master ⌚ 10:46:08 $ cd autoswitch_virtualenv WARNING: python binary not found on PATH.
zsh-autoswitch-virtualenv plugin will be disabled.

~/.oh-my-zsh/custom/plugins/autoswitch_virtualenv on  1070d49 ⌚ 10:46:09

Doesn't work with the branch either. I don't even have python (2.x) installed. I only have a python3. Running latest ubuntu.

-> when I press enter I get the WARNING.

doveppp commented 9 months ago

I'm testing it and it works too.

MichaelAquilina commented 8 months ago

Seems I forgot about this but should still work :) merged

ex37 commented 8 months ago

@MichaelAquilina this if statement https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv/blob/4ddc42d3d84bfb36fac1eb48e9e6de33a92fa4f1/autoswitch_virtualenv.plugin.zsh#L416 should also check for AUTOSWITCH_DEFAULT_PYTHON env variable, not just python, otherwise breaks setups like mine, where I don't have an alias for python and makes the whole point of AUTOSWITCH_DEFAULT_PYTHON useless