File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change
1
+ 0.4.1
2
+ -----
3
+
4
+ - fix bug where callbacks for historic hooks would not be called for
5
+ already registered plugins. Thanks Simon Gmizelj for the PR
6
+ and holger krekel for further fixes.
7
+
1
8
0.4.0
2
9
-----
3
10
Original file line number Diff line number Diff line change 67
67
import sys
68
68
import inspect
69
69
70
- __version__ = '0.4.0 '
70
+ __version__ = '0.4.1 '
71
71
72
72
__all__ = ["PluginManager" , "PluginValidationError" , "HookCallError" ,
73
73
"HookspecMarker" , "HookimplMarker" ]
@@ -745,11 +745,17 @@ def __call__(self, **kwargs):
745
745
return self ._hookexec (self , self ._nonwrappers + self ._wrappers , kwargs )
746
746
747
747
def call_historic (self , proc = None , kwargs = None ):
748
+ """ call the hook with given ``kwargs`` for all registered plugins and
749
+ for all plugins which will be registered afterwards.
750
+
751
+ If ``proc`` is not None it will be called for for each non-None result
752
+ obtained from a hook implementation.
753
+ """
748
754
self ._call_history .append ((kwargs or {}, proc ))
749
755
# historizing hooks don't return results
750
756
res = self ._hookexec (self , self ._nonwrappers + self ._wrappers , kwargs )
751
- if res and proc is not None :
752
- proc (res [ 0 ] )
757
+ for x in res or [] :
758
+ proc (x )
753
759
754
760
def call_extra (self , methods , kwargs ):
755
761
""" Call the hook with some additional temporarily participating
Original file line number Diff line number Diff line change @@ -212,24 +212,37 @@ def he_method1(self, arg):
212
212
pm .register (Plugin ())
213
213
assert l == [10 ]
214
214
215
- def test_with_immediate_result_memorized (self , pm ):
215
+ def test_with_callbacks_immediately_executed (self , pm ):
216
216
class Hooks :
217
217
@hookspec (historic = True )
218
218
def he_method1 (self , arg ):
219
219
pass
220
220
pm .add_hookspecs (Hooks )
221
221
222
- class Plugin :
222
+ class Plugin1 :
223
223
@hookimpl
224
224
def he_method1 (self , arg ):
225
225
return arg * 10
226
226
227
+ class Plugin2 :
228
+ @hookimpl
229
+ def he_method1 (self , arg ):
230
+ return arg * 20
231
+
232
+ class Plugin3 :
233
+ @hookimpl
234
+ def he_method1 (self , arg ):
235
+ return arg * 30
236
+
227
237
l = []
228
- pm .register (Plugin ())
238
+ pm .register (Plugin1 ())
239
+ pm .register (Plugin2 ())
229
240
230
241
he_method1 = pm .hook .he_method1
231
242
he_method1 .call_historic (lambda res : l .append (res ), dict (arg = 1 ))
232
- assert l == [10 ]
243
+ assert l == [20 , 10 ]
244
+ pm .register (Plugin3 ())
245
+ assert l == [20 , 10 , 30 ]
233
246
234
247
def test_register_historic_incompat_hookwrapper (self , pm ):
235
248
class Hooks :
You can’t perform that action at this time.
0 commit comments