Commits

Aron Griffis  committed 51a30a9 Merge

Merge upstream changes

  • Participants
  • Parent commits d11853f, 55759f9

Comments (0)

Files changed (3)

File docs/en/history.rst

   - Worked on some brittle tests.
   - Received updates to Japanese translation of the documentation from
     :bbuser:`t2y`.
+  - Fix the test script and runner so the user's ``$WORKON_HOME`` is
+    not erased if they do not have some test shells installed.
+    (big thanks to :bbuser:`agriffis`).
+  - If the hook loader is told to list plugins but is not given a hook
+    name, it prints the list of core hooks.
+  - Merge several fixes for path and variable handling for MSYS users
+    from :bbuser:`bwanamarko`. Includes a fix for :bbissue:`138`.
+  - Change :ref:`command-mkvirtualenv` so it catches both ``-h`` and
+    ``--help``.
+  - Fix some issues with the way temporary files are used for hook
+    scripts. (contributed by :bbuser:`agriffis`)
 
 3.2
 

File virtualenvwrapper.sh

         then
             echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2
         fi
-        mkdir -p $WORKON_HOME
+        mkdir -p "$WORKON_HOME"
         RC=$?
     fi
     return $RC
     echo;
     echo 'virtualenv help:';
     echo;
-    virtualenv -h;
+    virtualenv $@;
 }
 
 # Create a new environment, in the WORKON_HOME.
             -a)
                 i=$(( $i + 1 ));
                 project="${in_args[$i]}";;
-            -h)
-                mkvirtualenv_help;
+            -h|--help)
+                mkvirtualenv_help $a;
                 return;;
             -i)
                 i=$(( $i + 1 ));
 
 # Prints the path to the site-packages directory for the current environment.
 function virtualenvwrapper_get_site_packages_dir {
-    "$VIRTUAL_ENV/bin/python" -c "import distutils; print(distutils.sysconfig.get_python_lib())"
+    "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import distutils; print(distutils.sysconfig.get_python_lib())"
 }
 
 # Path management for packages outside of the virtual env.
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
-    ls $@ $site_packages
+    ls $@ "$site_packages"
 
     path_file="$site_packages/_virtualenv_path_extensions.pth"
     if [ -f "$path_file" ]
 
     cd "$PROJECT_HOME"
 
-    virtualenvwrapper_run_hook project.pre_mkproject $envname
+    virtualenvwrapper_run_hook "project.pre_mkproject" $envname
 
     echo "Creating $PROJECT_HOME/$envname"
     mkdir -p "$PROJECT_HOME/$envname"
         # For some reason zsh insists on prefixing the template
         # names with a space, so strip them out before passing
         # the value to the hook loader.
-        virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') project.template $envname
+        virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') "project.template" $envname
     done
 
-    virtualenvwrapper_run_hook project.post_mkproject
+    virtualenvwrapper_run_hook "project.post_mkproject"
 }
 
 # Change directory to the active project

File virtualenvwrapper/hook_loader.py

 """
 
 import inspect
+import itertools
 import logging
 import logging.handlers
 import optparse
 
 import pkg_resources
 
+
 class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
     """Taken from http://stackoverflow.com/questions/1407474/does-python-logging-handlers-rotatingfilehandler-allow-creation-of-a-group-writa
     """
         os.umask(prevumask)
         return rtv
 
+
 def main():
     parser = optparse.OptionParser(
         usage='usage: %prog [options] <hook> [<arguments>]',
                       dest='names',
                       default=[],
                       )
-    parser.disable_interspersed_args() # stop when we hit an option without an '-'
+    parser.disable_interspersed_args()  # stop when we hit an option without an '-'
     options, args = parser.parse_args()
 
     root_logger = logging.getLogger('')
 
     # Send higher-level messages to the console, too
     console = logging.StreamHandler()
-    console_level = [ logging.WARNING,
-                      logging.INFO,
-                      logging.DEBUG,
-                      ][options.verbose_level]
+    console_level = [logging.WARNING,
+                     logging.INFO,
+                     logging.DEBUG,
+                     ][options.verbose_level]
     console.setLevel(console_level)
     formatter = logging.Formatter('%(name)s %(message)s')
     console.setFormatter(formatter)
 
     # Determine which hook we're running
     if not args:
-        parser.error('Please specify the hook to run')
+        if options.listing:
+            list_hooks()
+            return 0
+        else:
+            parser.error('Please specify the hook to run')
     hook = args[0]
 
     if options.sourcing and options.script_filename:
 
     return 0
 
+
 def run_hooks(hook, options, args, output=None):
     if output is None:
         output = sys.stdout
             continue
         plugin = ep.load()
         if options.listing:
-            sys.stdout.write('  %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
+            output.write('  %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
             continue
         if options.sourcing:
             # Show the shell commands so they can
             # Just run the plugin ourselves
             plugin(args[1:])
 
+
+def list_hooks(output=None):
+    if output is None:
+        output = sys.stdout
+    for hook in itertools.chain(
+        ('_'.join(h)
+         for h in itertools.product(['pre', 'post'],
+                                    ['mkvirtualenv',
+                                     'rmvirtualenv',
+                                     'activate',
+                                     'deactivate',
+                                     'cpvirtualenv',
+                                     ])
+         ),
+        ['initialize',
+         'get_env_details',
+         'project.pre_mkproject',
+         'project.post_mkproject',
+         'project.template',
+         ]
+        ):
+        output.write(hook + '\n')
+
+
 if __name__ == '__main__':
     main()