@@ -337,55 +337,6 @@ def _hookexec(self, hook, methods, kwargs):
337
337
# enable_tracing will set its own wrapping function at self._inner_hookexec
338
338
return self ._inner_hookexec (hook , methods , kwargs )
339
339
340
- def add_hookcall_monitoring (self , before , after ):
341
- """ add before/after tracing functions for all hooks
342
- and return an undo function which, when called,
343
- will remove the added tracers.
344
-
345
- ``before(hook_name, hook_impls, kwargs)`` will be called ahead
346
- of all hook calls and receive a hookcaller instance, a list
347
- of HookImpl instances and the keyword arguments for the hook call.
348
-
349
- ``after(outcome, hook_name, hook_impls, kwargs)`` receives the
350
- same arguments as ``before`` but also a :py:class:`_CallOutcome`` object
351
- which represents the result of the overall hook call.
352
- """
353
- return _TracedHookExecution (self , before , after ).undo
354
-
355
- def enable_tracing (self ):
356
- """ enable tracing of hook calls and return an undo function. """
357
- hooktrace = self .hook ._trace
358
-
359
- def before (hook_name , methods , kwargs ):
360
- hooktrace .root .indent += 1
361
- hooktrace (hook_name , kwargs )
362
-
363
- def after (outcome , hook_name , methods , kwargs ):
364
- if outcome .excinfo is None :
365
- hooktrace ("finish" , hook_name , "-->" , outcome .result )
366
- hooktrace .root .indent -= 1
367
-
368
- return self .add_hookcall_monitoring (before , after )
369
-
370
- def subset_hook_caller (self , name , remove_plugins ):
371
- """ Return a new _HookCaller instance for the named method
372
- which manages calls to all registered plugins except the
373
- ones from remove_plugins. """
374
- orig = getattr (self .hook , name )
375
- plugins_to_remove = [plug for plug in remove_plugins if hasattr (plug , name )]
376
- if plugins_to_remove :
377
- hc = _HookCaller (orig .name , orig ._hookexec , orig ._specmodule_or_class ,
378
- orig .spec_opts )
379
- for hookimpl in (orig ._wrappers + orig ._nonwrappers ):
380
- plugin = hookimpl .plugin
381
- if plugin not in plugins_to_remove :
382
- hc ._add_hookimpl (hookimpl )
383
- # we also keep track of this hook caller so it
384
- # gets properly removed on plugin unregistration
385
- self ._plugin2hookcallers .setdefault (plugin , []).append (hc )
386
- return hc
387
- return orig
388
-
389
340
def register (self , plugin , name = None ):
390
341
""" Register a plugin and return its canonical name or None if the name
391
342
is blocked from registering. Raise a ValueError if the plugin is already
@@ -431,13 +382,6 @@ def parse_hookimpl_opts(self, plugin, name):
431
382
res = {}
432
383
return res
433
384
434
- def parse_hookspec_opts (self , module_or_class , name ):
435
- method = getattr (module_or_class , name )
436
- return getattr (method , self .project_name + "_spec" , None )
437
-
438
- def get_hookcallers (self , plugin ):
439
- return self ._plugin2hookcallers .get (plugin )
440
-
441
385
def unregister (self , plugin = None , name = None ):
442
386
""" unregister a plugin object and all its contained hook implementations
443
387
from internal data structures. """
@@ -488,6 +432,10 @@ def add_hookspecs(self, module_or_class):
488
432
raise ValueError ("did not find any %r hooks in %r" %
489
433
(self .project_name , module_or_class ))
490
434
435
+ def parse_hookspec_opts (self , module_or_class , name ):
436
+ method = getattr (module_or_class , name )
437
+ return getattr (method , self .project_name + "_spec" , None )
438
+
491
439
def get_plugins (self ):
492
440
""" return the set of registered plugins. """
493
441
return set (self ._plugin2hookcallers )
@@ -566,6 +514,60 @@ def list_name_plugin(self):
566
514
""" return list of name/plugin pairs. """
567
515
return list (self ._name2plugin .items ())
568
516
517
+ def get_hookcallers (self , plugin ):
518
+ """ get all hook callers for the specified plugin. """
519
+ return self ._plugin2hookcallers .get (plugin )
520
+
521
+ def add_hookcall_monitoring (self , before , after ):
522
+ """ add before/after tracing functions for all hooks
523
+ and return an undo function which, when called,
524
+ will remove the added tracers.
525
+
526
+ ``before(hook_name, hook_impls, kwargs)`` will be called ahead
527
+ of all hook calls and receive a hookcaller instance, a list
528
+ of HookImpl instances and the keyword arguments for the hook call.
529
+
530
+ ``after(outcome, hook_name, hook_impls, kwargs)`` receives the
531
+ same arguments as ``before`` but also a :py:class:`_CallOutcome`` object
532
+ which represents the result of the overall hook call.
533
+ """
534
+ return _TracedHookExecution (self , before , after ).undo
535
+
536
+ def enable_tracing (self ):
537
+ """ enable tracing of hook calls and return an undo function. """
538
+ hooktrace = self .hook ._trace
539
+
540
+ def before (hook_name , methods , kwargs ):
541
+ hooktrace .root .indent += 1
542
+ hooktrace (hook_name , kwargs )
543
+
544
+ def after (outcome , hook_name , methods , kwargs ):
545
+ if outcome .excinfo is None :
546
+ hooktrace ("finish" , hook_name , "-->" , outcome .result )
547
+ hooktrace .root .indent -= 1
548
+
549
+ return self .add_hookcall_monitoring (before , after )
550
+
551
+ def subset_hook_caller (self , name , remove_plugins ):
552
+ """ Return a new _HookCaller instance for the named method
553
+ which manages calls to all registered plugins except the
554
+ ones from remove_plugins. """
555
+ orig = getattr (self .hook , name )
556
+ plugins_to_remove = [plug for plug in remove_plugins if hasattr (plug , name )]
557
+ if plugins_to_remove :
558
+ hc = _HookCaller (orig .name , orig ._hookexec , orig ._specmodule_or_class ,
559
+ orig .spec_opts )
560
+ for hookimpl in (orig ._wrappers + orig ._nonwrappers ):
561
+ plugin = hookimpl .plugin
562
+ if plugin not in plugins_to_remove :
563
+ hc ._add_hookimpl (hookimpl )
564
+ # we also keep track of this hook caller so it
565
+ # gets properly removed on plugin unregistration
566
+ self ._plugin2hookcallers .setdefault (plugin , []).append (hc )
567
+ return hc
568
+ return orig
569
+
570
+
569
571
570
572
class _MultiCall :
571
573
""" execute a call into multiple python functions/methods. """
0 commit comments