Skip to content

Commit ea26ed6

Browse files
committed
addresses ticket 35 by adding debugging instrumentation
1 parent 0f4544f commit ea26ed6

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2010-05-16 Doug Hellmann <[email protected]>
2+
3+
* virtualenvwrapper/hook_loader.py (main): Add more debug logging
4+
to try to narrow down the tempfile issue (#35).
5+
6+
* virtualenvwrapper.sh (virtualenvwrapper_run_hook): Add more
7+
debugging error reporting to try to narrow down the tempfile
8+
issue (#35).
9+
110
2010-05-09 Doug Hellmann <[email protected]>
211

312
* virtualenvwrapper.sh: Tweak path normalization code so double

tests/test_tempfile.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
test_dir=$(dirname $0)
66

77
export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
8+
export HOOK_VERBOSE_OPTION=-v
89

910
oneTimeSetUp() {
1011
rm -rf "$WORKON_HOME"
@@ -29,4 +30,26 @@ test_tempfile () {
2930
assertTrue "virtualenvwrapper-hook not in filename." "echo $filename | grep virtualenvwrapper-hook"
3031
}
3132

33+
test_no_such_tmpdir () {
34+
old_tmpdir="$TMPDIR"
35+
TMPDIR="$TMPDIR/does-not-exist"
36+
virtualenvwrapper_run_hook "initialize" >/dev/null 2>&1
37+
RC=$?
38+
assertSame "Unexpected exit code $RC" "1" "$RC"
39+
TMPDIR="$old_tmpdir"
40+
}
41+
42+
test_tmpdir_not_writable () {
43+
old_tmpdir="$TMPDIR"
44+
TMPDIR="$TMPDIR/cannot-write"
45+
mkdir "$TMPDIR"
46+
chmod ugo-w "$TMPDIR"
47+
virtualenvwrapper_run_hook "initialize" >/dev/null 2>&1
48+
RC=$?
49+
assertSame "Unexpected exit code $RC" "1" "$RC"
50+
chmod ugo+w "$TMPDIR"
51+
rmdir "$TMPDIR"
52+
TMPDIR="$old_tmpdir"
53+
}
54+
3255
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,21 @@ virtualenvwrapper_tempfile () {
9999
# Run the hooks
100100
virtualenvwrapper_run_hook () {
101101
typeset hook_script="$(virtualenvwrapper_tempfile ${1}-hook)"
102+
if [ -z "$hook_script" ]
103+
then
104+
echo "ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2
105+
return 1
106+
fi
102107
"$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
103108
result=$?
104109

105110
if [ $result -eq 0 ]
106111
then
112+
if [ ! -f "$hook_script" ]
113+
then
114+
echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2
115+
return 2
116+
fi
107117
source "$hook_script"
108118
fi
109119
rm -f "$hook_script" >/dev/null 2>&1
@@ -116,7 +126,7 @@ virtualenvwrapper_initialize () {
116126
virtualenvwrapper_run_hook "initialize"
117127
if [ $? -ne 0 ]
118128
then
119-
echo "virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
129+
echo "virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
120130
return 1
121131
fi
122132
}

virtualenvwrapper/hook_loader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,17 @@ def main():
9999
if options.sourcing:
100100
hook += '_source'
101101

102+
log = logging.getLogger(__name__)
103+
104+
log.debug('Running %s hooks', hook)
102105
run_hooks(hook, options, args)
103106

104107
if options.script_filename:
108+
log.debug('Saving sourcable %s hooks to %s', hook, options.script_filename)
105109
options.sourcing = True
106110
output = open(options.script_filename, "w")
107111
try:
112+
output.write('# %s\n' % hook)
108113
run_hooks(hook + '_source', options, args, output)
109114
finally:
110115
output.close()

0 commit comments

Comments
 (0)