Commits

Doug Hellmann committed 34cb8e5

convert hook loader to use stevedore

  • Participants
  • Parent commits 2a15b93

Comments (0)

Files changed (5)

File docs/en/history.rst

 
 dev
 
+  - Switch to stevedore_ for plugin management
+
+.. _stevedore: http://pypi.python.org/pypi/stevedore
+
+3.5
+
   - Rewrite :ref:`command-cpvirtualenv` to use `virtualenv-clone`_
     instead of making the new environment relocatable. Contributed by
     Justin Barber (:bbuser:`barberj`). This also resolves a problem
               ],
     install_requires=['virtualenv',
                       'virtualenv-clone',
+                      'stevedore',
                       ],
 
     namespace_packages = [ 'virtualenvwrapper' ],

File tests/test.sh

     cd "$WORKON_HOME"
     mkvirtualenv no_wrappers >/dev/null 2>&1
 	RC=$?
-	assertEquals "0" "$RC"
+	assertEquals "mkvirtualenv return code wrong" "0" "$RC"
     expected="ImportError: No module named virtualenvwrapper.hook_loader"
     # test_shell is set by tests/run_tests
     if [ "$test_shell" = "" ]
 commands = bash ./tests/run_tests {envdir} []
 deps = virtualenv
        virtualenv-clone
+       stevedore
 setenv =
     TOXIC = true
 

File virtualenvwrapper/hook_loader.py

 import os
 import sys
 
-import pkg_resources
+from stevedore import ExtensionManager
+from stevedore import NamedExtensionManager
 
 
 class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
     if output is None:
         output = sys.stdout
 
-    for ep in pkg_resources.iter_entry_points('virtualenvwrapper.%s' % hook):
-        if options.names and ep.name not in options.names:
-            continue
-        plugin = ep.load()
-        if options.listing:
-            output.write('  %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
-            continue
-        if options.sourcing:
+    namespace = 'virtualenvwrapper.%s' % hook
+    if options.names:
+        hook_mgr = NamedExtensionManager(namespace, options.names)
+    else:
+        hook_mgr = ExtensionManager(namespace)
+
+    if options.listing:
+        def show(ext):
+            output.write('  %-10s -- %s\n' % (ext.name, inspect.getdoc(ext.plugin) or ''))
+        hook_mgr.map(show)
+
+    elif options.sourcing:
+        def get_source(ext, args):
             # Show the shell commands so they can
             # be run in the calling shell.
-            contents = (plugin(args[1:]) or '').strip()
+            contents = (ext.plugin(args) or '').strip()
             if contents:
-                output.write('# %s\n' % ep.name)
+                output.write('# %s\n' % ext.name)
                 output.write(contents)
                 output.write("\n")
-        else:
-            # Just run the plugin ourselves
-            plugin(args[1:])
+        try:
+            hook_mgr.map(get_source, args[1:])
+        except RuntimeError:
+            pass
+
+    else:
+        # Just run the plugin ourselves
+        def invoke(ext, args):
+            ext.plugin(args)
+        try:
+            hook_mgr.map(invoke, args[1:])
+        except RuntimeError:
+            pass
 
 
 def list_hooks(output=None):