Commits

Doug Hellmann  committed 5fdf2d1

fix use of sed in add2virtualenv to be more portable

  • Participants
  • Parent commits 6a47fb9

Comments (0)

Files changed (3)

File docs/en/history.rst

 Release History
 ===============
 
+dev
+
+  - Incorporated patch to add ``-d`` option to
+    :ref:`command-add2virtualenv`, contributed by :bbuser:`miracle2k`.
+
 2.9
 
   - Change the shell function shell definition syntax so that ksh will

File tests/test_add2virtualenv.sh

     cdsitepackages
     # Check contents of path file
     path_file="./_virtualenv_path_extensions.pth"
-    assertTrue "No $full_path in `cat $path_file`" "grep $full_path $path_file"
-    assertTrue "No path insert code in `cat $path_file`" "grep sys.__egginsert $path_file"
+    assertTrue "No $full_path in $(cat $path_file)" "grep $full_path $path_file"
+    assertTrue "No path insert code in $(cat $path_file)" "grep sys.__egginsert $path_file"
     # Check the path we inserted is actually at the top
     expected=$full_path
     actual=$($WORKON_HOME/pathtest/bin/python -c "import sys; print sys.path[1]")
     assertSame "$expected" "$actual"
+
+    # Make sure the temporary file created
+    # during the edit was removed
+    assertFalse "Temporary file ${path_file}.tmp still exists" "[ -f ${path_file}.tmp ]"
+
     cd -
 }
 

File virtualenvwrapper.sh

 # site-packages directory; if this file does not exist, it will be
 # created first.
 function add2virtualenv {
-
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     
 
         if [ $remove -eq 1 ]
         then
-            sed -i "\:^$absolute_path$: d" "$path_file"
+            sed -i.tmp "\:^$absolute_path$: d" "$path_file"
         else
-            sed -i "1a $absolute_path" "$path_file"
+            sed -i.tmp '1 a\
+'$absolute_path'
+' "$path_file"
         fi
+        rm -f "${path_file}.tmp"
     done
     return 0
 }