b033440741fb3f1dc5ae1bb6b0134388503fafe0

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #144 from hauntsaninja/poetry

Fix _activate_poetry in case of multiple poetry venvs

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index c6de88b0a3693dd47cdab2a33469532675cea7d0..74c67501afe5d13f970d472dca888cb7b922de9a 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -142,7 +142,7 @@ function _check_path()
 6 function _activate_poetry() {
 7     # check if any environments exist before trying to activate
 8     # if env list is empty, then no environment exists that can be activated
 9-    local name="$(poetry env list --full-path | cut -d' ' -f1)"
10+    local name="$(poetry env list --full-path | sort -k 2 | tail -n 1 | cut -d' ' -f1)"
11     if [[ -n "$name" ]]; then
12         _maybeworkon "$name" "poetry"
13         return 0
14diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
15index df9295283ba1800a43333e3079bdf88288099397..7ee686a82b5cbca6f4143bc5aaafb51efe205888 100644
16--- a/tests/test_check_venv.zunit
17+++ b/tests/test_check_venv.zunit
18@@ -178,7 +178,7 @@
19 
20     # Mimic "poetry env list --full-path"
21     function poetry {
22-        echo "$HOME/.cache/pypoetry/virtualenvs/poetry-foo (Activated)"
23+        echo "$HOME/.cache/pypoetry/virtualenvs/some-other-env\n$HOME/.cache/pypoetry/virtualenvs/poetry-foo (Activated)"
24     }
25 
26     run check_venv