Skip to content

Commit 659748f

Browse files
committed
another attempt to address #35
1 parent 66d0bde commit 659748f

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2010-04-26 Doug Hellmann <[email protected]>
2+
3+
* virtualenvwrapper.sh (virtualenvwrapper_tempfile): Add a suffix
4+
to the tempfile name so we know the tempfile module isn't going to
5+
erase it.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ help:
2020
@echo "website - build web version of docs"
2121
@echo "installwebsite - deploy web version of docs"
2222
@echo "develop - install development version"
23+
@echo "test - run the test suite"
2324

2425

2526
.PHONY: sdist

tests/test_tempfile.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ setUp () {
2323
}
2424

2525
test_tempfile () {
26-
filename=$(virtualenvwrapper_tempfile)
26+
filename=$(virtualenvwrapper_tempfile hook)
2727
rm -f $filename
2828
assertSame "$TMPDIR" "$(dirname $filename)/"
2929
assertTrue "echo $filename | grep virtualenvwrapper"
@@ -32,11 +32,11 @@ test_tempfile () {
3232
test_no_python () {
3333
old=$VIRTUALENVWRAPPER_PYTHON
3434
VIRTUALENVWRAPPER_PYTHON=false
35-
filename=$(virtualenvwrapper_tempfile)
35+
filename=$(virtualenvwrapper_tempfile hook)
3636
VIRTUALENVWRAPPER_PYTHON=$old
3737
rm -f $filename
38-
assertSame "$TMPDIR" "$(dirname $filename)/"
39-
assertTrue "echo $filename | grep virtualenvwrapper.$$"
38+
assertSame "TMPDIR and path not the same for $filename." "$TMPDIR" "$(dirname $filename)/"
39+
assertTrue "virtualenvwrapper and pid not in filename." "echo $filename | grep virtualenvwrapper.$$"
4040
}
4141

4242
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ virtualenvwrapper_verify_workon_home () {
7676

7777
# Use Python's tempfile module to create a temporary file
7878
# with a unique and not-likely-to-be-predictable name.
79+
# Expects 1 argument, the suffix for the new file.
7980
virtualenvwrapper_tempfile () {
80-
$VIRTUALENVWRAPPER_PYTHON -c "import tempfile; print tempfile.NamedTemporaryFile(prefix='virtualenvwrapper.').name"
81-
if [ $? -ne 0 ]
81+
typeset base=$("$VIRTUALENVWRAPPER_PYTHON" -c "import tempfile; print tempfile.NamedTemporaryFile(prefix='virtualenvwrapper.').name")
82+
if [ -z "$base" ]
8283
then
83-
echo "${TMPDIR:-/tmp}/virtualenvwrapper.$$.`date +%s`"
84+
echo "${TMPDIR:-/tmp}/virtualenvwrapper.$$.`date +%s`.$1"
85+
else
86+
echo "$base.$1"
8487
fi
8588
}
8689

@@ -89,7 +92,7 @@ virtualenvwrapper_run_hook () {
8992
# First anything that runs directly from the plugin
9093
"$VIRTUALENVWRAPPER_PYTHON" -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION "$@"
9194
# Now anything that wants to run inside this shell
92-
hook_script=$(virtualenvwrapper_tempfile)
95+
hook_script="$(virtualenvwrapper_tempfile hook)"
9396
"$VIRTUALENVWRAPPER_PYTHON" -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION \
9497
--source "$@" >>"$hook_script"
9598
source "$hook_script"

0 commit comments

Comments
 (0)