Diff
1diff --git a/CHANGELOG.rst b/CHANGELOG.rst
2index cc3adc70f53cf9f08e1f10b2055c42c74b7b2375..e21475d5bb693a9a318be891cd431c6f44547115 100644
3--- a/CHANGELOG.rst
4+++ b/CHANGELOG.rst
5@@ -1,6 +1,10 @@
6 Changelog
7 =========
8
9+1.11.0
10+------
11+* Correct project detection behaviour when working with pipenv
12+
13 1.10.1
14 ------
15 * Fix minor bug where variables would leak into user's environment
16diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
17index 54a2e6b05b930fab1a6a38571a254d18f2a48be2..7961f0ed32dc07aa02ab910d7fd62264a082cfdd 100644
18--- a/autoswitch_virtualenv.plugin.zsh
19+++ b/autoswitch_virtualenv.plugin.zsh
20@@ -1,4 +1,4 @@
21-export AUTOSWITCH_VERSION='1.10.1'
22+export AUTOSWITCH_VERSION='1.11.0'
23
24 RED="\e[31m"
25 GREEN="\e[32m"
26@@ -6,18 +6,6 @@ PURPLE="\e[35m"
27 BOLD="\e[1m"
28 NORMAL="\e[0m"
29
30-
31-if ! type "virtualenv" > /dev/null; then
32- export DISABLE_AUTOSWITCH_VENV="1"
33- printf "${BOLD}${RED}"
34- printf "zsh-autoswitch-virtualenv requires virtualenv to be installed!\n\n"
35- printf "${NORMAL}"
36- printf "If this is already installed but you are still seeing this message, \n"
37- printf "then make sure the ${BOLD}virtualenv${NORMAL} command is in your PATH.\n"
38- printf "\n"
39-fi
40-
41-
42 function _virtual_env_dir() {
43 local venv_name="$1"
44 local VIRTUAL_ENV_DIR="${AUTOSWITCH_VIRTUAL_ENV_DIR:-$HOME/.virtualenvs}"
45@@ -125,19 +113,23 @@ function check_venv()
46 else
47 SWITCH_TO="$(<"$venv_path")"
48 fi
49- elif [[ -f "$PWD/requirements.txt" || -f "$PWD/setup.py" ]]; then
50- printf "Python project detected. "
51- printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
52 fi
53
54 if [[ -n "$SWITCH_TO" ]]; then
55 _maybeworkon "$(_virtual_env_dir "$SWITCH_TO")" "virtualenv"
56
57- # check if Pipfile exists rather than invoking pipenv as it is slow
58+ # check if Pipfile exists rather than invoking pipenv as it is slow
59 elif [[ -a "Pipfile" ]] && type "pipenv" > /dev/null; then
60 venv_path="$(PIPENV_IGNORE_VIRTUALENVS=1 pipenv --venv)"
61 _maybeworkon "$venv_path" "pipenv"
62 else
63+ if [[ -f "$PWD/Pipfile" ]]; then
64+ printf "Python project detected. "
65+ printf "Run ${PURPLE}pipenv install${NORMAL} to setup autoswitching\n"
66+ elif [[ -f "$PWD/requirements.txt" || -f "$PWD/setup.py" ]]; then
67+ printf "Python project detected. "
68+ printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
69+ fi
70 _default_venv
71 fi
72 }
73@@ -264,7 +256,14 @@ function disable_autoswitch_virtualenv() {
74 }
75
76
77-if [[ -z "$DISABLE_AUTOSWITCH_VENV" ]]; then
78+if ! type "virtualenv" > /dev/null; then
79+ printf "${BOLD}${RED}"
80+ printf "zsh-autoswitch-virtualenv requires virtualenv to be installed!\n\n"
81+ printf "${NORMAL}"
82+ printf "If this is already installed but you are still seeing this message, \n"
83+ printf "then make sure the ${BOLD}virtualenv${NORMAL} command is in your PATH.\n"
84+ printf "\n"
85+else
86 enable_autoswitch_virtualenv
87 check_venv
88 fi
89diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
90index 586e64879953eae116dc75be798803d35ef2a3e7..ae0754202c076d31872fd7a1ec3d3e8760a88fc6 100644
91--- a/tests/test_check_venv.zunit
92+++ b/tests/test_check_venv.zunit
93@@ -45,6 +45,16 @@
94 assert "$output" same_as "Python project detected. Run \e[35mmkvenv\e[0m to setup autoswitching"
95 }
96
97+@test 'check_venv - Displays message on project detection (Pipfile)' {
98+ PWD="$TARGET"
99+ touch "$TARGET/Pipfile"
100+
101+ run check_venv
102+
103+ assert $status equals 0
104+ assert "$output" same_as "Python project detected. Run \e[35mpipenv install\e[0m to setup autoswitching"
105+}
106+
107 @test 'check_venv - Displays message on project detection (setup.py + requirements.txt)' {
108 PWD="$TARGET"
109 touch "$TARGET/setup.py"