Diff
1diff --git a/.circleci/config.yml b/.circleci/config.yml
2index 6d029c4bf9505bf456b61ba46cd0899b5793a0a8..a80807c937e3243f78ddc4e93850458597d70482 100644
3--- a/.circleci/config.yml
4+++ b/.circleci/config.yml
5@@ -6,10 +6,7 @@ test: &test
6 - checkout
7 - run:
8 name: Install Dependencies
9- command: apt-get update && apt-get install -y curl python3-pip python3.4-dev ncurses-bin python python-virtualenv git
10- - run:
11- name: install virtualenvwrapper
12- command: pip3 install virtualenvwrapper
13+ command: apt-get update && apt-get install -y curl python3-pip ncurses-bin python python-virtualenv git
14 - run:
15 name: install pipenv
16 command: pip3 install pipenv
17@@ -26,7 +23,6 @@ test: &test
18 # Required by pipenv to work correctly
19 export LC_ALL=C.UTF-8
20 export LANG=C.UTF-8
21- export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 # We have to manually set this for some reason
22 export TERM="xterm-256color" # Required by tput
23 export PATH="$HOME/bin:$PATH"
24 zunit --verbose
25diff --git a/README.rst b/README.rst
26index 2636f42c44aa99def9c9080d00d5014b135a80ef..99fd6ad4642fedd779fcc2c849cf11a54b74cb69 100644
27--- a/README.rst
28+++ b/README.rst
29@@ -9,7 +9,6 @@ virtualenvs automatically as you move between directories.
30 * `How it Works`_
31 * `More Details`_
32 * Installing_
33-* Setup_
34 * `Pipenv Integration`_
35 * Commands_
36 * Options_
37@@ -67,36 +66,6 @@ Zgen_
38
39 zgen load "MichaelAquilina/zsh-autoswitch-virtualenv"
40
41-Setup
42------
43-
44-``virtualenvwrapper`` must be installed for this plugin to work
45-correctly. You should install it with pip:
46-
47-::
48-
49- pip install virtualenvwrapper
50-
51-You need to source this file in your ``.zshrc`` file as part of your
52-setup. This should work:
53-
54-::
55-
56- source =virtualenvwrapper.sh
57-
58-**IMPORTANT:** Make sure this is put *before* your package manager loading code (i.e. the
59-line of code discussed in the section that follows).
60-
61-In combination, your ``.zshrc`` file should look something like this (if you
62-are using zplug)
63-
64-::
65-
66- zplug "MichaelAquilina/zsh-autoswitch-virtualenv"
67- source =virtualenvwrapper.sh
68-
69- zplug load
70-
71 Pipenv Integration
72 ------------------
73
74@@ -131,7 +100,7 @@ Optionally, you can specify the python binary to use for this virtual environmen
75
76 $ mkvenv --python=/usr/bin/python3
77
78-In fact, ``mkvenv`` supports any parameters that can be passed to ``mkvirtualenv``
79+In fact, ``mkvenv`` supports any parameters that can be passed to ``python -m virtualenv``
80
81 ``mkvenv`` will create a virtual environment with the same name as the
82 current directory, suggest installing ``requirements.txt`` if available
83diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
84index ee0aee05e24c606f300ff29a637a2a32f2cb3689..32655558170846f3014958063bbffcfc5f51eda6 100644
85--- a/autoswitch_virtualenv.plugin.zsh
86+++ b/autoswitch_virtualenv.plugin.zsh
87@@ -1,26 +1,15 @@
88 export AUTOSWITCH_VERSION='0.7.0'
89
90+# TODO: Possibly allow the user to modify this if they wish
91+VIRTUAL_ENV_DIR="$HOME/.virtualenvs"
92+mkdir -p "$VIRTUAL_ENV_DIR"
93+
94 RED="\e[31m"
95 GREEN="\e[32m"
96 PURPLE="\e[35m"
97 BOLD="\e[1m"
98 NORMAL="\e[0m"
99
100-if ! type workon > /dev/null; then
101- export DISABLE_AUTOSWITCH_VENV="1"
102- printf "${BOLD}${RED}"
103- printf "zsh-autoswitch-virtualenv requires virtualenvwrapper to be installed!\n\n"
104- printf "${NORMAL}"
105- printf "If this is already installed but you are still seeing this message, \nadd the "
106- printf "following to your ~/.zshrc:\n\n"
107- printf "${BOLD}"
108- printf "source =virtualenvwrapper.sh\n"
109- printf "\n"
110- printf "${NORMAL}"
111- printf "https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv#Setup"
112- printf "\n"
113-fi
114-
115 function _print_python_version() {
116 # For some reason python --version writes to stderr
117 if type python > /dev/null; then
118@@ -40,7 +29,7 @@ function _maybeworkon() {
119 fi
120
121 # Much faster to source the activate file directly rather than use the `workon` command
122- source "$HOME/.virtualenvs/$1/bin/activate"
123+ source "$VIRTUAL_ENV_DIR/$1/bin/activate"
124
125 if [ -z "$AUTOSWITCH_SILENT" ]; then
126 _print_python_version
127@@ -156,7 +145,8 @@ function rmvenv()
128 fi
129 fi
130
131- rmvirtualenv "$venv_name"
132+ printf "Removing %s...\n" "$venv_name"
133+ rm -rf "$VIRTUAL_ENV_DIR/$venv_name"
134 rm ".venv"
135 else
136 printf "No .venv file in the current directory!\n"
137@@ -171,8 +161,22 @@ function mkvenv()
138 printf ".venv file already exists. If this is a mistake use the rmvenv command\n"
139 else
140 venv_name="$(basename $PWD)"
141- mkvirtualenv "$venv_name" $@
142
143+ printf "Creating ${PURPLE}%s${NONE} virtualenv\n" "$venv_name"
144+ # TODO: Allow verbose option to remove suppressing details
145+ virtualenv $@ "$VIRTUAL_ENV_DIR/$venv_name" > /dev/null
146+
147+ printf "$venv_name\n" > ".venv"
148+ chmod 600 .venv
149+
150+ _maybeworkon "$venv_name"
151+
152+ install_requirements
153+ fi
154+}
155+
156+
157+function install_requirements() {
158 setopt nullglob
159 for requirements in *requirements.txt
160 do
161@@ -183,12 +187,9 @@ function mkvenv()
162 pip install -r "$requirements"
163 fi
164 done
165- printf "$venv_name\n" > ".venv"
166- chmod 600 .venv
167- AUTOSWITCH_PROJECT="$PWD"
168- fi
169 }
170
171+
172 if [[ -z "$DISABLE_AUTOSWITCH_VENV" ]]; then
173 autoload -Uz add-zsh-hook
174 add-zsh-hook -D chpwd check_venv
175diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
176index 28a24c0f26a6150e515c8a7590f6104038562cd6..e627c3b5014a6db64733d769d5108dd1cd327264 100644
177--- a/tests/test_check_venv.zunit
178+++ b/tests/test_check_venv.zunit
179@@ -1,15 +1,14 @@
180 #!/usr/bin/env zunit
181
182 @setup {
183- source =virtualenvwrapper.sh
184
185 if [[ ! -d "$HOME/.virtualenvs/foobar/" ]]; then
186 echo "Creating test virtualenv"
187- run mkvirtualenv foobar --python=python3
188+ run python -m virtualenv "$HOME/.virtualenvs/foobar" --python=python3
189 fi
190 if [[ ! -d "$HOME/.virtualenvs/foodefault/" ]]; then
191 echo "Creating default test virtualenv"
192- run mkvirtualenv foodefault --python=python3
193+ run python -m virtualenv "$HOME/.virtualenvs/foodefault" --python=python3
194 fi
195
196 PYTHON_VERSION="$(python3 --version 2>&1)"
197diff --git a/tests/test_check_venv_path.zunit b/tests/test_check_venv_path.zunit
198index 0d0ca34b172143e4308cb6681da9b0cfcfb21ca7..c844f40caa06de10a203ab1ff7c053bc0be6cf17 100644
199--- a/tests/test_check_venv_path.zunit
200+++ b/tests/test_check_venv_path.zunit
201@@ -2,7 +2,6 @@
202
203
204 @setup {
205- source =virtualenvwrapper.sh
206 export DISABLE_AUTOSWITCH_VENV="1"
207 load "../autoswitch_virtualenv.plugin.zsh"
208 TARGET="$(mktemp -d)"
209diff --git a/tests/test_help.zunit b/tests/test_help.zunit
210deleted file mode 100644
211index 7d1d8854651c55fbbaffb25d7a5424e8701ee3f3..0000000000000000000000000000000000000000
212--- a/tests/test_help.zunit
213+++ /dev/null
214@@ -1,16 +0,0 @@
215-#!/usr/bin/env zunit
216-
217-@test 'prints help message and disables plugin if virtualenvwrapper not setup' {
218- run load ../autoswitch_virtualenv.plugin.zsh
219-
220- assert $status equals 0
221- assert "$lines[1]" contains "zsh-autoswitch-virtualenv requires virtualenvwrapper to be installed!"
222- assert "$lines[2]" is_empty
223- assert "$lines[3]" contains "If this is already installed but you are still seeing this message,"
224- assert "$lines[4]" contains "add the following to your ~/.zshrc"
225- assert "$lines[5]" is_empty
226- assert "$lines[6]" contains "source =virtualenvwrapper.sh"
227- assert "$lines[7]" is_empty
228- assert "$lines[8]" contains "https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv#Setup"
229- assert ${#lines} equals 8
230-}
231diff --git a/tests/test_maybepipenv.zunit b/tests/test_maybepipenv.zunit
232index 7753d8920fecd3a61cafa06034c31173ea1d5fd9..ed03b9712a79f98a7b5ce317bc6a223120029850 100644
233--- a/tests/test_maybepipenv.zunit
234+++ b/tests/test_maybepipenv.zunit
235@@ -1,7 +1,6 @@
236 #!/usr/bin/env zunit
237
238 @setup {
239- source =virtualenvwrapper.sh
240
241 if ! type "pipenv" > /dev/null; then
242 skip "You need to install pipenv to run these tests"
243diff --git a/tests/test_maybeworkon.zunit b/tests/test_maybeworkon.zunit
244index 3ac6771f290e1ef0462a26cf01e89b090d1bbf68..7af6531af8768942f08a4eeeebb438c96e9c6065 100644
245--- a/tests/test_maybeworkon.zunit
246+++ b/tests/test_maybeworkon.zunit
247@@ -2,11 +2,10 @@
248
249
250 @setup {
251- source =virtualenvwrapper.sh
252
253 if [[ ! -d "$HOME/.virtualenvs/foobar/" ]]; then
254 echo "Creating test virtualenv"
255- run mkvirtualenv foobar --python=python3
256+ run python -m virtualenv "$HOME/.virtualenvs/foobar" --python=python3
257 fi
258
259 PYTHON_VERSION="$(python3 --version 2>&1)"
260diff --git a/tests/test_mkvenv.zunit b/tests/test_mkvenv.zunit
261index 3e3beb25e2d73d0f6694a37a26f32140fbb1c43e..6a5c384a115529fdf9e2d1c2079bde72cfa3187c 100644
262--- a/tests/test_mkvenv.zunit
263+++ b/tests/test_mkvenv.zunit
264@@ -1,7 +1,6 @@
265 #!/usr/bin/env zunit
266
267 @setup {
268- source =virtualenvwrapper.sh
269
270 export DISABLE_AUTOSWITCH_VENV="1"
271 load "../autoswitch_virtualenv.plugin.zsh"
272@@ -30,7 +29,6 @@
273 run mkvenv
274
275 assert $status equals 0
276- assert "$output" contains "New python executable"
277 assert "$TARGET/myproject/.venv" exists
278
279 run cat "$TARGET/myproject/.venv"
280diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit
281index 3ce656bd453cf9a9dd69b042b4518071c364bf83..5a9a3bffd002389ead0c373797b250cb32f51d4a 100644
282--- a/tests/test_plugin.zunit
283+++ b/tests/test_plugin.zunit
284@@ -1,11 +1,9 @@
285 #!/usr/bin/env zunit
286
287 @setup {
288- load =virtualenvwrapper.sh
289-
290 if [[ ! -d "$HOME/.virtualenvs/foobar/" ]]; then
291 echo "Creating test virtualenv"
292- run mkvirtualenv foobar --python=python3
293+ run python -m virtualenv "$HOME/.virtualenvs/foobar" --python=python3
294 fi
295 unset VIRTUAL_ENV
296 PYTHON_VERSION="$(python3 --version)"
297diff --git a/tests/test_rmvenv.zunit b/tests/test_rmvenv.zunit
298index 3be698bb120cbba4a129c6627c6ab8c726eb0208..2c8d53703304437d752e7a0c33b434e0bd27ccb4 100644
299--- a/tests/test_rmvenv.zunit
300+++ b/tests/test_rmvenv.zunit
301@@ -1,7 +1,6 @@
302 #!/usr/bin/env zunit
303
304 @setup {
305- source =virtualenvwrapper.sh
306
307 export DISABLE_AUTOSWITCH_VENV="1"
308 load "../autoswitch_virtualenv.plugin.zsh"