Skip to content

Commit c91167d

Browse files
committed
Ensure that -p and --python options are consistent
The option parsing in mkvirtualenv was not handling the long-form of --python with the value attached to the same argument using = (it only worked if the option and value were separate command line arguments). Addresses issue #190. Signed-off-by: Doug Hellmann <[email protected]>
1 parent f9bc8f5 commit c91167d

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

docs/source/history.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ dev
1313
API commands that trigger the lazy-loader by extending
1414
``_VIRTUALENVWRAPPER_API``. Patch contributed by John Purnell, see
1515
:bbissue:`188`.
16+
- Fix detection of ``--python`` option to
17+
:ref:`command-mkvirtualenv`. Resolves :bbissue:`190`.
1618

1719
4.0
1820
===

tests/test_mkvirtualenv.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,29 @@ test_mkvirtualenv_python_not_sticky () {
196196
VIRTUALENVWRAPPER_VIRTUALENV=$_save
197197
}
198198

199+
test_mkvirtualenv_python_short_option () {
200+
typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV
201+
VIRTUALENVWRAPPER_VIRTUALENV=echo
202+
output="$(mkvirtualenv -p python foo)"
203+
assertSame "--python=$(pwd)/python foo" "$output"
204+
VIRTUALENVWRAPPER_VIRTUALENV=$_save
205+
}
206+
207+
test_mkvirtualenv_python_long_option () {
208+
typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV
209+
VIRTUALENVWRAPPER_VIRTUALENV=echo
210+
output="$(mkvirtualenv --python python foo)"
211+
assertSame "--python=$(pwd)/python foo" "$output"
212+
VIRTUALENVWRAPPER_VIRTUALENV=$_save
213+
}
214+
215+
test_mkvirtualenv_python_long_option_equal () {
216+
typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV
217+
VIRTUALENVWRAPPER_VIRTUALENV=echo
218+
output="$(mkvirtualenv --python=python foo)"
219+
assertSame "--python=$(pwd)/python foo" "$output"
220+
VIRTUALENVWRAPPER_VIRTUALENV=$_save
221+
}
222+
199223

200224
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,14 @@ function mkvirtualenv {
408408
-i)
409409
i=$(( $i + 1 ));
410410
packages="$packages ${in_args[$i]}";;
411-
-p|--python)
412-
i=$(( $i + 1 ));
413-
interpreter="${in_args[$i]}";
411+
-p|--python*)
412+
if echo "$a" | grep -q "="
413+
then
414+
interpreter="$(echo "$a" | cut -f2 -d=)"
415+
else
416+
i=$(( $i + 1 ))
417+
interpreter="${in_args[$i]}"
418+
fi;
414419
interpreter="$(virtualenvwrapper_absolutepath "$interpreter")";;
415420
-r)
416421
i=$(( $i + 1 ));

0 commit comments

Comments
 (0)