also incrementally remove plugins from hook callers
--HG-- branch : more_plugin
This commit is contained in:
parent
02a4042dca
commit
f41528433b
|
@ -185,7 +185,7 @@ class PluginManager(object):
|
||||||
for plugin in hc.plugins:
|
for plugin in hc.plugins:
|
||||||
meth = getattr(plugin, name, None)
|
meth = getattr(plugin, name, None)
|
||||||
if meth is not None:
|
if meth is not None:
|
||||||
hc._add_method(meth)
|
hc.add_method(meth)
|
||||||
return hc
|
return hc
|
||||||
|
|
||||||
def register(self, plugin, name=None):
|
def register(self, plugin, name=None):
|
||||||
|
@ -219,8 +219,7 @@ class PluginManager(object):
|
||||||
del self._name2plugin[name]
|
del self._name2plugin[name]
|
||||||
hookcallers = self._plugin2hookcallers.pop(plugin)
|
hookcallers = self._plugin2hookcallers.pop(plugin)
|
||||||
for hookcaller in hookcallers:
|
for hookcaller in hookcallers:
|
||||||
hookcaller.plugins.remove(plugin)
|
hookcaller.remove_plugin(plugin)
|
||||||
hookcaller._scan_methods()
|
|
||||||
|
|
||||||
def addhooks(self, module_or_class):
|
def addhooks(self, module_or_class):
|
||||||
""" add new hook definitions from the given module_or_class using
|
""" add new hook definitions from the given module_or_class using
|
||||||
|
@ -242,7 +241,7 @@ class PluginManager(object):
|
||||||
hc.setspec(firstresult=firstresult, argnames=argnames)
|
hc.setspec(firstresult=firstresult, argnames=argnames)
|
||||||
for plugin in hc.plugins:
|
for plugin in hc.plugins:
|
||||||
self._verify_hook(hc, specfunc, plugin)
|
self._verify_hook(hc, specfunc, plugin)
|
||||||
hc._add_method(getattr(plugin, name))
|
hc.add_method(getattr(plugin, name))
|
||||||
names.append(name)
|
names.append(name)
|
||||||
if not names:
|
if not names:
|
||||||
raise ValueError("did not find new %r hooks in %r"
|
raise ValueError("did not find new %r hooks in %r"
|
||||||
|
@ -292,7 +291,7 @@ class PluginManager(object):
|
||||||
# we have a hook spec, can verify early
|
# we have a hook spec, can verify early
|
||||||
self._verify_hook(hook, method, plugin)
|
self._verify_hook(hook, method, plugin)
|
||||||
hook.plugins.append(plugin)
|
hook.plugins.append(plugin)
|
||||||
hook._add_method(method)
|
hook.add_method(method)
|
||||||
hookcallers.append(hook)
|
hookcallers.append(hook)
|
||||||
return hookcallers
|
return hookcallers
|
||||||
|
|
||||||
|
@ -420,13 +419,15 @@ class HookCaller:
|
||||||
self.argnames = ["__multicall__"] + list(argnames)
|
self.argnames = ["__multicall__"] + list(argnames)
|
||||||
self.firstresult = firstresult
|
self.firstresult = firstresult
|
||||||
|
|
||||||
def _scan_methods(self):
|
def remove_plugin(self, plugin):
|
||||||
self.wrappers[:] = []
|
self.plugins.remove(plugin)
|
||||||
self.nonwrappers[:] = []
|
meth = getattr(plugin, self.name)
|
||||||
for plugin in self.plugins:
|
try:
|
||||||
self._add_method(getattr(plugin, self.name))
|
self.nonwrappers.remove(meth)
|
||||||
|
except ValueError:
|
||||||
|
self.wrappers.remove(meth)
|
||||||
|
|
||||||
def _add_method(self, meth):
|
def add_method(self, meth):
|
||||||
assert not self.pre
|
assert not self.pre
|
||||||
if hasattr(meth, 'hookwrapper'):
|
if hasattr(meth, 'hookwrapper'):
|
||||||
self.wrappers.append(meth)
|
self.wrappers.append(meth)
|
||||||
|
|
|
@ -96,7 +96,7 @@ class TestAddMethodOrdering:
|
||||||
func.trylast = True
|
func.trylast = True
|
||||||
if hookwrapper:
|
if hookwrapper:
|
||||||
func.hookwrapper = True
|
func.hookwrapper = True
|
||||||
hc._add_method(func)
|
hc.add_method(func)
|
||||||
return func
|
return func
|
||||||
return wrap
|
return wrap
|
||||||
return addmeth
|
return addmeth
|
||||||
|
|
Loading…
Reference in New Issue