d807b9d47f0b2dd290cd6bb120f1da77a1ed5377
- Author
- Michael Aquilina <michaelaquilina@gmail.com>
- Committer
- Michael Aquilina <michaelaquilina@gmail.com>
- Date
Message
Correct python project detection for pipenv
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index d9ffb930dc98cbf512fc28f23d12a618f3376f39..7d78f5ff98710c2647d6b8668693e5c202d9b8d5 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -113,19 +113,23 @@ function check_venv()
6 else
7 SWITCH_TO="$(<"$venv_path")"
8 fi
9- elif [[ -f "$PWD/requirements.txt" || -f "$PWD/setup.py" ]]; then
10- printf "Python project detected. "
11- printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
12 fi
13
14 if [[ -n "$SWITCH_TO" ]]; then
15 _maybeworkon "$(_virtual_env_dir "$SWITCH_TO")" "virtualenv"
16
17- # check if Pipfile exists rather than invoking pipenv as it is slow
18+ # check if Pipfile exists rather than invoking pipenv as it is slow
19 elif [[ -a "Pipfile" ]] && type "pipenv" > /dev/null; then
20 venv_path="$(PIPENV_IGNORE_VIRTUALENVS=1 pipenv --venv)"
21 _maybeworkon "$venv_path" "pipenv"
22 else
23+ if [[ -f "$PWD/Pipfile" ]]; then
24+ printf "Python project detected. "
25+ printf "Run ${PURPLE}pipenv install${NORMAL} to setup autoswitching\n"
26+ elif [[ -f "$PWD/requirements.txt" || -f "$PWD/setup.py" ]]; then
27+ printf "Python project detected. "
28+ printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
29+ fi
30 _default_venv
31 fi
32 }
33diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
34index 586e64879953eae116dc75be798803d35ef2a3e7..ae0754202c076d31872fd7a1ec3d3e8760a88fc6 100644
35--- a/tests/test_check_venv.zunit
36+++ b/tests/test_check_venv.zunit
37@@ -45,6 +45,16 @@
38 assert "$output" same_as "Python project detected. Run \e[35mmkvenv\e[0m to setup autoswitching"
39 }
40
41+@test 'check_venv - Displays message on project detection (Pipfile)' {
42+ PWD="$TARGET"
43+ touch "$TARGET/Pipfile"
44+
45+ run check_venv
46+
47+ assert $status equals 0
48+ assert "$output" same_as "Python project detected. Run \e[35mpipenv install\e[0m to setup autoswitching"
49+}
50+
51 @test 'check_venv - Displays message on project detection (setup.py + requirements.txt)' {
52 PWD="$TARGET"
53 touch "$TARGET/setup.py"