Skip to content

Commit 34cb8e5

Browse files
committed
convert hook loader to use stevedore
1 parent 2a15b93 commit 34cb8e5

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

docs/en/history.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Release History
44

55
dev
66

7+
- Switch to stevedore_ for plugin management
8+
9+
.. _stevedore: http://pypi.python.org/pypi/stevedore
10+
11+
3.5
12+
713
- Rewrite :ref:`command-cpvirtualenv` to use `virtualenv-clone`_
814
instead of making the new environment relocatable. Contributed by
915
Justin Barber (:bbuser:`barberj`). This also resolves a problem

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def find_package_data(
149149
],
150150
install_requires=['virtualenv',
151151
'virtualenv-clone',
152+
'stevedore',
152153
],
153154

154155
namespace_packages = [ 'virtualenvwrapper' ],

tests/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ test_python_interpreter_set_incorrectly() {
8686
cd "$WORKON_HOME"
8787
mkvirtualenv no_wrappers >/dev/null 2>&1
8888
RC=$?
89-
assertEquals "0" "$RC"
89+
assertEquals "mkvirtualenv return code wrong" "0" "$RC"
9090
expected="ImportError: No module named virtualenvwrapper.hook_loader"
9191
# test_shell is set by tests/run_tests
9292
if [ "$test_shell" = "" ]

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ envlist = py27,py26,py32
55
commands = bash ./tests/run_tests {envdir} []
66
deps = virtualenv
77
virtualenv-clone
8+
stevedore
89
setenv =
910
TOXIC = true
1011

virtualenvwrapper/hook_loader.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import os
1414
import sys
1515

16-
import pkg_resources
16+
from stevedore import ExtensionManager
17+
from stevedore import NamedExtensionManager
1718

1819

1920
class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
@@ -138,24 +139,39 @@ def run_hooks(hook, options, args, output=None):
138139
if output is None:
139140
output = sys.stdout
140141

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):
149155
# Show the shell commands so they can
150156
# be run in the calling shell.
151-
contents = (plugin(args[1:]) or '').strip()
157+
contents = (ext.plugin(args) or '').strip()
152158
if contents:
153-
output.write('# %s\n' % ep.name)
159+
output.write('# %s\n' % ext.name)
154160
output.write(contents)
155161
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
159175

160176

161177
def list_hooks(output=None):

0 commit comments

Comments
 (0)