Skip to content

Commit 1bfc94a

Browse files
committed
fix use of sed in add2virtualenv to be more portable
1 parent 3d152cb commit 1bfc94a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

docs/en/history.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Release History
33
===============
44

5+
dev
6+
7+
- Incorporated patch to add ``-d`` option to
8+
:ref:`command-add2virtualenv`, contributed by :bbuser:`miracle2k`.
9+
510
2.9
611

712
- Change the shell function shell definition syntax so that ksh will

tests/test_add2virtualenv.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ test_add2virtualenv () {
2828
cdsitepackages
2929
# Check contents of path file
3030
path_file="./_virtualenv_path_extensions.pth"
31-
assertTrue "No $full_path in `cat $path_file`" "grep $full_path $path_file"
32-
assertTrue "No path insert code in `cat $path_file`" "grep sys.__egginsert $path_file"
31+
assertTrue "No $full_path in $(cat $path_file)" "grep $full_path $path_file"
32+
assertTrue "No path insert code in $(cat $path_file)" "grep sys.__egginsert $path_file"
3333
# Check the path we inserted is actually at the top
3434
expected=$full_path
3535
actual=$($WORKON_HOME/pathtest/bin/python -c "import sys; print sys.path[1]")
3636
assertSame "$expected" "$actual"
37+
38+
# Make sure the temporary file created
39+
# during the edit was removed
40+
assertFalse "Temporary file ${path_file}.tmp still exists" "[ -f ${path_file}.tmp ]"
41+
3742
cd -
3843
}
3944

virtualenvwrapper.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ function virtualenvwrapper_get_site_packages_dir {
579579
# site-packages directory; if this file does not exist, it will be
580580
# created first.
581581
function add2virtualenv {
582-
583582
virtualenvwrapper_verify_workon_home || return 1
584583
virtualenvwrapper_verify_active_environment || return 1
585584

@@ -630,10 +629,13 @@ function add2virtualenv {
630629

631630
if [ $remove -eq 1 ]
632631
then
633-
sed -i "\:^$absolute_path$: d" "$path_file"
632+
sed -i.tmp "\:^$absolute_path$: d" "$path_file"
634633
else
635-
sed -i "1a $absolute_path" "$path_file"
634+
sed -i.tmp '1 a\
635+
'$absolute_path'
636+
' "$path_file"
636637
fi
638+
rm -f "${path_file}.tmp"
637639
done
638640
return 0
639641
}

0 commit comments

Comments
 (0)