Diff
1diff --git a/CHANGELOG.rst b/CHANGELOG.rst
2index 37a82beb895617e9932f682f2ec8afcdd9b3ac08..c23ec8c60ff29872625069bd9b945a906aa0b1a8 100644
3--- a/CHANGELOG.rst
4+++ b/CHANGELOG.rst
5@@ -1,6 +1,12 @@
6 Changelog
7 =========
8
9+1.10.0
10+------
11+* Scan for requirements files recursively when setting up a virtualenv (#88 - fix by @nrc)
12+* Fix bug when `rm` was aliased to a different behaviour (#87 - fix by @rnc)
13+* Invoke pip install in editable (i.e. development) mode. (#91 - fix by @rnc)
14+
15 1.9.0
16 -----
17 * Show message when deactivating virtual environments
18diff --git a/README.rst b/README.rst
19index cbf37438d4a0fe358bab304297021e87dc053996..365fc3fc48782afaa378d77275ffb391768be53b 100644
20--- a/README.rst
21+++ b/README.rst
22@@ -296,6 +296,13 @@ the same location that the ``virtualenvwrapper`` package uses.
23 If you wish to change this to another location, simply set the value of the
24 environment variable ``AUTOSWITCH_VIRTUAL_ENV_DIR``.
25
26+**Customising pip install invocation**
27+
28+By default `mkvenv` will install setup.py via pip in editable (i.e. development) mode. See
29+`here <http://codumentary.blogspot.com/2014/11/python-tip-of-year-pip-install-editable.html/>`__
30+and `here <https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs/>`__ for
31+further information. To change this set ``AUTOSWITCH_PIPINSTALL`` to ``FULL``.
32+
33 Security Warnings
34 -----------------
35
36diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
37index 0ed093723537ad3773acec15ccaf6d015e6d5760..f152273fb1aeea42d82906dd41c595fe761aeb25 100644
38--- a/autoswitch_virtualenv.plugin.zsh
39+++ b/autoswitch_virtualenv.plugin.zsh
40@@ -1,4 +1,4 @@
41-export AUTOSWITCH_VERSION='1.9.0'
42+export AUTOSWITCH_VERSION='1.10.0'
43
44 RED="\e[31m"
45 GREEN="\e[32m"
46@@ -167,8 +167,12 @@ function rmvenv()
47 fi
48
49 printf "Removing ${PURPLE}%s${NORMAL}...\n" "$venv_name"
50- rm -rf "$(_virtual_env_dir "$venv_name")"
51- rm ".venv"
52+ # Using explicit paths to avoid any alias/function interference.
53+ # rm should always be found in this location according to
54+ # https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s04.html
55+ # https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/
56+ /bin/rm -rf "$(_virtual_env_dir "$venv_name")"
57+ /bin/rm ".venv"
58 else
59 printf "No .venv file in the current directory!\n"
60 fi
61@@ -223,12 +227,17 @@ function install_requirements() {
62 read ans
63
64 if [[ "$ans" = "y" || "$ans" = "Y" ]]; then
65- pip install .
66+ if [[ "$AUTOSWITCH_PIPINSTALL" = "FULL" ]]
67+ then
68+ pip install .
69+ else
70+ pip install -e .
71+ fi
72 fi
73 fi
74
75 setopt nullglob
76- for requirements in *requirements.txt
77+ for requirements in **/*requirements.txt
78 do
79 printf "Found a ${PURPLE}%s${NORMAL} file. Install? [y/N]: " "$requirements"
80 read ans
81diff --git a/tests/test_install_requirements.txt b/tests/test_install_requirements.zunit
82rename from tests/test_install_requirements.txt
83rename to tests/test_install_requirements.zunit
84index 5ad700495bb58597646086c83d80a8b32b5d3d9e..33be19c130a54d6b49af538f1a085c23704f4d6a 100644
85--- a/tests/test_install_requirements.txt
86+++ b/tests/test_install_requirements.zunit
87@@ -98,6 +98,46 @@
88
89 run install_requirements
90
91+ assert $status equals 0
92+ assert "$lines[1]" same_as "Found a \e[35msetup.py\e[0m file. Install dependencies? [y/N]: y"
93+ assert "$lines[2]" same_as "pip install -e ."
94+}
95+
96+@test 'install_requirements - installs recursive *requirements.txt' {
97+ echo "django" > requirements.txt
98+ mkdir subdir
99+ echo "pytest" > subdir/dev-requirements.txt
100+
101+ # mock pip to make it testable
102+ function pip {
103+ echo "pip $@"
104+ cat "$3"
105+ }
106+
107+ run install_requirements
108+ echo "output is $output"
109+
110+ assert $status equals 0
111+ assert "$lines[1]" same_as "Found a \e[35mrequirements.txt\e[0m file. Install? [y/N]: y"
112+ assert "$lines[2]" same_as "pip install -r requirements.txt"
113+ assert "$lines[3]" same_as "django"
114+ assert "$lines[4]" same_as "Found a \e[35msubdir/dev-requirements.txt\e[0m file. Install? [y/N]: y"
115+ assert "$lines[5]" same_as "pip install -r subdir/dev-requirements.txt"
116+ assert "$lines[6]" same_as "pytest"
117+}
118+
119+@test 'install_requirements - installs setup.py' {
120+ touch "setup.py"
121+ echo "django" > requirements.txt
122+
123+ # mock pip to make it testable
124+ function pip {
125+ echo "pip $@"
126+ }
127+ local AUTOSWITCH_PIPINSTALL="FULL"
128+
129+ run install_requirements
130+
131 assert $status equals 0
132 assert "$lines[1]" same_as "Found a \e[35msetup.py\e[0m file. Install dependencies? [y/N]: y"
133 assert "$lines[2]" same_as "pip install ."
134diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit
135index ec88b24f20efdf7687aef82bd478b0f91ee1d9d1..2ed87a420545e112b3bbc8598c4e9d94456b27cb 100644
136--- a/tests/test_plugin.zunit
137+++ b/tests/test_plugin.zunit
138@@ -14,7 +14,7 @@
139 unset AUTOSWITCH_DEFAULTENV
140 load ../autoswitch_virtualenv.plugin.zsh
141
142- git_version="$(git tag --list | sort | tail -1)"
143+ git_version="$(git tag --list | sort -V | tail -1)"
144 git tag --list
145
146 assert "$AUTOSWITCH_VERSION" is_not_empty
147diff --git a/tests/test_rmvenv.zunit b/tests/test_rmvenv.zunit
148index fdce5fa59c46cc445f442c98687d22ebfde9815f..0e1b51df1ebc7c34fce96e0212e4824a95a496b8 100644
149--- a/tests/test_rmvenv.zunit
150+++ b/tests/test_rmvenv.zunit
151@@ -36,6 +36,23 @@
152 test ! -d "$HOME/.virtualenvs/12345"
153 }
154
155+@test 'rmvenv - removes .venv if present with function' {
156+ # lightweight simulation of creating a virtualenv
157+ mkdir -p "$HOME/.virtualenvs/54321"
158+
159+ echo "54321" > .venv
160+
161+ # Interfere with rm executable (in normal use alias or function would do the same).
162+ function rm(){ : }
163+
164+ run rmvenv
165+
166+ assert $state equals 0
167+ assert "$output" same_as "Removing \e[35m54321\e[0m..."
168+ test ! -f .venv
169+ test ! -d "$HOME/.virtualenvs/54321"
170+}
171+
172 @test 'rmvenv - removes .venv and deactivates if currently active' {
173 test_venv="$(basename $PWD)"
174 run mkvenv