3727dbfabcad0fc82bdb9b64a4cc972e246b42d0
- Author
- Michael Aquilina <michaelaquilina@gmail.com>
- Committer
- Michael Aquilina <michaelaquilina@gmail.com>
- Date
Message
Improve check performance by avoiding to run pipenv
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index 33fccbc0b69d369368cf8907e70cb940f938882e..bcf50b5739a03b5c3fade378c12916e1dcf61736 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -119,7 +119,9 @@ function check_venv()
6
7 if [[ -n "$SWITCH_TO" ]]; then
8 _maybeworkon "$SWITCH_TO"
9- elif [[ -n `pipenv --venv 2>/dev/null` ]]; then
10+
11+ # check if Pipfile exists rather than invoking pipenv as it is slow
12+ elif [[ -a "Pipfile" ]] && type "pipenv" > /dev/null; then
13 _maybepipenv "$(pipenv --venv)"
14 else
15 _default_venv
16diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
17index 63d5d44dc9fc8a8965867af0dbc6ce870e8a8cd4..28a24c0f26a6150e515c8a7590f6104038562cd6 100644
18--- a/tests/test_check_venv.zunit
19+++ b/tests/test_check_venv.zunit
20@@ -22,6 +22,7 @@
21
22 @teardown {
23 rm -rf "$TARGET"
24+ rm -rf Pipfile
25 }
26
27
28@@ -128,10 +129,11 @@
29 }
30
31
32-@test 'check_venv - deactivate if .venv unavailable but pipenv available' {
33+@test 'check_venv - activate if .venv unavailable but pipenv available' {
34 PWD="$TARGET"
35 MYOLDPWD="$(dirname $TARGET)"
36 VIRTUAL_ENV="foo"
37+ touch "Pipfile"
38
39 function pipenv {
40 echo "$HOME/.virtualenvs/foobar"