e0be4cd16cbac44255c35dc8de3a437ab127a36d

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

Message

Merge pull request #130 from hauntsaninja/patch-1

Silence spurious errors from dirname

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index 91fafeca53825a591c19f59ca46763275c81afad..2568e816785ee00ef52b9c9a39424fb08364cf8c 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -187,9 +187,11 @@ function check_venv()
 6         # we need to infer the target virtualenv directory based on poetry's data
 7         # to easiest way is to actually get the location of the python binary and
 8         # infer the location of the virtualenv from there.
 9-        if venv_path="$(dirname $(dirname $(poetry run which python)))"; then
10-            _maybeworkon "$venv_path" "poetry"
11-            return
12+        if poetry_python=$(poetry run which python); then
13+            if venv_path="$(dirname $(dirname $poetry_python))"; then
14+                _maybeworkon "$venv_path" "poetry"
15+                return
16+            fi
17         fi
18     fi
19 
20diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
21index 968024c0516304345643106a9e52f72e1541727a..538ec46957bb35e1cbd93dc723c481722fa3f30c 100644
22--- a/tests/test_check_venv.zunit
23+++ b/tests/test_check_venv.zunit
24@@ -167,6 +167,15 @@
25 
26     assert $status equals 0
27     assert "$output" same_as "Switching poetry: \e[1m\e[35mfoobar\e[0m \e[32m[🐍$PYTHON_VERSION]\e[0m"
28+
29+    # poetry available, but "poetry run which python" fails because pyproject.toml doesn't use poetry
30+    function poetry {
31+        return 1
32+    }
33+
34+    run check_venv
35+    assert $status equals 0
36+    assert "$output" is_empty
37 }
38 
39