Commits

Doug Hellmann committed c91167d

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 <doug.hellmann@gmail.com>

Comments (0)

Files changed (3)

docs/source/history.rst

   API commands that trigger the lazy-loader by extending
   ``_VIRTUALENVWRAPPER_API``. Patch contributed by John Purnell, see
   :bbissue:`188`.
+- Fix detection of ``--python`` option to
+  :ref:`command-mkvirtualenv`. Resolves :bbissue:`190`.
 
 4.0
 ===

tests/test_mkvirtualenv.sh

     VIRTUALENVWRAPPER_VIRTUALENV=$_save
 }
 
+test_mkvirtualenv_python_short_option () {
+    typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV
+    VIRTUALENVWRAPPER_VIRTUALENV=echo
+    output="$(mkvirtualenv -p python foo)"
+    assertSame "--python=$(pwd)/python foo" "$output"
+    VIRTUALENVWRAPPER_VIRTUALENV=$_save
+}
+
+test_mkvirtualenv_python_long_option () {
+    typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV
+    VIRTUALENVWRAPPER_VIRTUALENV=echo
+    output="$(mkvirtualenv --python python foo)"
+    assertSame "--python=$(pwd)/python foo" "$output"
+    VIRTUALENVWRAPPER_VIRTUALENV=$_save
+}
+
+test_mkvirtualenv_python_long_option_equal () {
+    typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV
+    VIRTUALENVWRAPPER_VIRTUALENV=echo
+    output="$(mkvirtualenv --python=python foo)"
+    assertSame "--python=$(pwd)/python foo" "$output"
+    VIRTUALENVWRAPPER_VIRTUALENV=$_save
+}
+
 
 . "$test_dir/shunit2"

virtualenvwrapper.sh

             -i)
                 i=$(( $i + 1 ));
                 packages="$packages ${in_args[$i]}";;
-            -p|--python)
-                i=$(( $i + 1 ));
-                interpreter="${in_args[$i]}";
+            -p|--python*)
+                if echo "$a" | grep -q "="
+                then
+                    interpreter="$(echo "$a" | cut -f2 -d=)"
+                else
+                    i=$(( $i + 1 ))
+                    interpreter="${in_args[$i]}"
+                fi;
                 interpreter="$(virtualenvwrapper_absolutepath "$interpreter")";;
             -r)
                 i=$(( $i + 1 ));