Doug Hellmann avatar Doug Hellmann committed 7369884

addresses ticket 35 by adding debugging instrumentation

Comments (0)

Files changed (4)

+2010-05-16  Doug Hellmann  <dhellmann@racemi.com>
+
+	* virtualenvwrapper/hook_loader.py (main): Add more debug logging
+	to try to narrow down the tempfile issue (#35).
+
+	* virtualenvwrapper.sh (virtualenvwrapper_run_hook): Add more
+	debugging error reporting to try to narrow down the tempfile
+	issue (#35).
+
 2010-05-09  Doug Hellmann  <dhellmann@racemi.com>
 
 	* virtualenvwrapper.sh: Tweak path normalization code so double

tests/test_tempfile.sh

 test_dir=$(dirname $0)
 
 export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+export HOOK_VERBOSE_OPTION=-v
 
 oneTimeSetUp() {
     rm -rf "$WORKON_HOME"
     assertTrue "virtualenvwrapper-hook not in filename." "echo $filename | grep virtualenvwrapper-hook"
 }
 
+test_no_such_tmpdir () {
+    old_tmpdir="$TMPDIR"
+    TMPDIR="$TMPDIR/does-not-exist"
+    virtualenvwrapper_run_hook "initialize" >/dev/null 2>&1
+    RC=$?
+    assertSame "Unexpected exit code $RC" "1" "$RC"
+    TMPDIR="$old_tmpdir"
+}
+
+test_tmpdir_not_writable () {
+    old_tmpdir="$TMPDIR"
+    TMPDIR="$TMPDIR/cannot-write"
+    mkdir "$TMPDIR"
+    chmod ugo-w "$TMPDIR"
+    virtualenvwrapper_run_hook "initialize" >/dev/null 2>&1
+    RC=$?
+    assertSame "Unexpected exit code $RC" "1" "$RC"
+    chmod ugo+w "$TMPDIR"
+    rmdir "$TMPDIR"
+    TMPDIR="$old_tmpdir"
+}
+
 . "$test_dir/shunit2"

virtualenvwrapper.sh

 # Run the hooks
 virtualenvwrapper_run_hook () {
     typeset hook_script="$(virtualenvwrapper_tempfile ${1}-hook)"
+    if [ -z "$hook_script" ]
+    then
+        echo "ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2
+        return 1
+    fi
     "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
     result=$?
     
     if [ $result -eq 0 ]
     then
+        if [ ! -f "$hook_script" ]
+        then
+            echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2
+            return 2
+        fi
         source "$hook_script"
     fi
     rm -f "$hook_script" >/dev/null 2>&1
     virtualenvwrapper_run_hook "initialize"
     if [ $? -ne 0 ]
     then
-        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
+        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
         return 1
     fi
 }

virtualenvwrapper/hook_loader.py

     if options.sourcing:
         hook += '_source'
 
+    log = logging.getLogger(__name__)
+
+    log.debug('Running %s hooks', hook)
     run_hooks(hook, options, args)
 
     if options.script_filename:
+        log.debug('Saving sourcable %s hooks to %s', hook, options.script_filename)
         options.sourcing = True
         output = open(options.script_filename, "w")
         try:
+            output.write('# %s\n' % hook)
             run_hooks(hook + '_source', options, args, output)
         finally:
             output.close()
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.