Doug Hellmann avatar Doug Hellmann committed 160207c

change mktmpenv to always create an env name for the user; addresses #114

Comments (0)

Files changed (4)

docs/en/command_ref.rst

 
 Syntax::
 
-    mktmpenv [ENVNAME]
+    mktmpenv [VIRTUALENV_OPTIONS]
 
-If no environment name is given, a temporary unique name is generated.
+A unique virtualenv name is generated.
 
 ::
 

docs/en/history.rst

 Release History
 ===============
 
+dev
+
+  - Changed arguments to :ref:`command-mktmpenv` so it always creates
+    an environment name for you. (:bbissue:`114`)
+
 2.10
 
   - Incorporated patch to add ``-d`` option to

tests/test_mktmpenv.sh

 }
 
 test_mktmpenv_name() {
-    assertFalse "Environment already exists" "[ -d \"$WORKON_HOME/name-given-by-user\" ]"
     mktmpenv name-given-by-user >/dev/null 2>&1
-    assertTrue "Environment was not created" "[ -d \"$WORKON_HOME/name-given-by-user\" ]"
-    assertSame $(basename "$VIRTUAL_ENV") "name-given-by-user"
+    RC=$?
+    assertTrue "Error was not detected" "[ $RC -ne 0 ]"
+}
+
+test_mktmpenv_virtualenv_args() {
+    mktmpenv --no-site-packages >/dev/null 2>&1
+    RC=$?
+    assertTrue "Error was detected" "[ $RC -eq 0 ]"
 }
 
 test_deactivate() {
-    assertFalse "Environment already exists" "[ -d \"$WORKON_HOME/automatically-deleted\" ]"
-    mktmpenv automatically-deleted >/dev/null 2>&1
-    assertSame $(basename "$VIRTUAL_ENV") "automatically-deleted"
-    assertTrue "Environment was not created" "[ -d \"$WORKON_HOME/automatically-deleted\" ]"
+    mktmpenv >/dev/null 2>&1
+    assertTrue "Environment was not created" "[ ! -z \"$VIRTUAL_ENV\" ]"
+    env_name=$(basename "$VIRTUAL_ENV")
     deactivate >/dev/null 2>&1
-    assertFalse "Environment still exists" "[ -d \"$WORKON_HOME/automatically-deleted\" ]"
+    assertFalse "Environment still exists" "[ -d \"$WORKON_HOME/$env_name\" ]"
 }
 
 . "$test_dir/shunit2"

virtualenvwrapper.sh

 #
 mktmpenv() {
     typeset tmpenvname
+    typeset RC
 
-    # Generate a unique temporary name, if one is not given.
-    if [ $# -eq 0 ]
+    # Generate a unique temporary name
+    tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import uuid; print uuid.uuid4()' 2>/dev/null)
+    if [ -z "$tmpenvname" ]
     then
-        tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import uuid; print uuid.uuid4()' 2>/dev/null)
-        if [ -z "$tmpenvname" ]
-        then
-            # This python does not support uuid
-            tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import random; print hex(random.getrandbits(64))[2:-1]' 2>/dev/null)
-        fi
-        mkvirtualenv "$tmpenvname"
-    else
-        mkvirtualenv "$@"
+        # This python does not support uuid
+        tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import random; print hex(random.getrandbits(64))[2:-1]' 2>/dev/null)
     fi
 
     # Create the environment
+    mkvirtualenv "$@" "$tmpenvname"
     RC=$?
     if [ $RC -ne 0 ]
     then
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.