|
13 | 13 | import os |
14 | 14 | import sys |
15 | 15 |
|
16 | | -import pkg_resources |
| 16 | +from stevedore import ExtensionManager |
| 17 | +from stevedore import NamedExtensionManager |
17 | 18 |
|
18 | 19 |
|
19 | 20 | class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler): |
@@ -138,24 +139,39 @@ def run_hooks(hook, options, args, output=None): |
138 | 139 | if output is None: |
139 | 140 | output = sys.stdout |
140 | 141 |
|
141 | | - for ep in pkg_resources.iter_entry_points('virtualenvwrapper.%s' % hook): |
142 | | - if options.names and ep.name not in options.names: |
143 | | - continue |
144 | | - plugin = ep.load() |
145 | | - if options.listing: |
146 | | - output.write(' %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or '')) |
147 | | - continue |
148 | | - if options.sourcing: |
| 142 | + namespace = 'virtualenvwrapper.%s' % hook |
| 143 | + if options.names: |
| 144 | + hook_mgr = NamedExtensionManager(namespace, options.names) |
| 145 | + else: |
| 146 | + hook_mgr = ExtensionManager(namespace) |
| 147 | + |
| 148 | + if options.listing: |
| 149 | + def show(ext): |
| 150 | + output.write(' %-10s -- %s\n' % (ext.name, inspect.getdoc(ext.plugin) or '')) |
| 151 | + hook_mgr.map(show) |
| 152 | + |
| 153 | + elif options.sourcing: |
| 154 | + def get_source(ext, args): |
149 | 155 | # Show the shell commands so they can |
150 | 156 | # be run in the calling shell. |
151 | | - contents = (plugin(args[1:]) or '').strip() |
| 157 | + contents = (ext.plugin(args) or '').strip() |
152 | 158 | if contents: |
153 | | - output.write('# %s\n' % ep.name) |
| 159 | + output.write('# %s\n' % ext.name) |
154 | 160 | output.write(contents) |
155 | 161 | output.write("\n") |
156 | | - else: |
157 | | - # Just run the plugin ourselves |
158 | | - plugin(args[1:]) |
| 162 | + try: |
| 163 | + hook_mgr.map(get_source, args[1:]) |
| 164 | + except RuntimeError: |
| 165 | + pass |
| 166 | + |
| 167 | + else: |
| 168 | + # Just run the plugin ourselves |
| 169 | + def invoke(ext, args): |
| 170 | + ext.plugin(args) |
| 171 | + try: |
| 172 | + hook_mgr.map(invoke, args[1:]) |
| 173 | + except RuntimeError: |
| 174 | + pass |
159 | 175 |
|
160 | 176 |
|
161 | 177 | def list_hooks(output=None): |
|
0 commit comments