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 @@ -221,24 +221,37 @@ def he_method1(self, arg):
221
221
pm .register (Plugin ())
222
222
assert l == [10 ]
223
223
224
- def test_with_immediate_result_memorized (self , pm ):
224
+ def test_with_callbacks_immediately_executed (self , pm ):
225
225
class Hooks :
226
226
@hookspec (historic = True )
227
227
def he_method1 (self , arg ):
228
228
pass
229
229
pm .add_hookspecs (Hooks )
230
230
231
- class Plugin :
231
+ class Plugin1 :
232
232
@hookimpl
233
233
def he_method1 (self , arg ):
234
234
return arg * 10
235
235
236
+ class Plugin2 :
237
+ @hookimpl
238
+ def he_method1 (self , arg ):
239
+ return arg * 20
240
+
241
+ class Plugin3 :
242
+ @hookimpl
243
+ def he_method1 (self , arg ):
244
+ return arg * 30
245
+
236
246
l = []
237
- pm .register (Plugin ())
247
+ pm .register (Plugin1 ())
248
+ pm .register (Plugin2 ())
238
249
239
250
he_method1 = pm .hook .he_method1
240
251
he_method1 .call_historic (lambda res : l .append (res ), dict (arg = 1 ))
241
- assert l == [10 ]
252
+ assert l == [20 , 10 ]
253
+ pm .register (Plugin3 ())
254
+ assert l == [20 , 10 , 30 ]
242
255
243
256
def test_register_historic_incompat_hookwrapper (self , pm ):
244
257
class Hooks :
You can’t perform that action at this time.
0 commit comments