@@ -186,8 +186,8 @@ decorators are used to *mark* functions for detection by a ``PluginManager``:
186
186
187
187
from pluggy import HookspecMarker, HookimplMarker
188
188
189
- hookspec = HookspecMarker(' project_name' )
190
- hookimpl = HookimplMarker(' project_name' )
189
+ hookspec = HookspecMarker(" project_name" )
190
+ hookimpl = HookimplMarker(" project_name" )
191
191
192
192
193
193
Each decorator type takes a single ``project_name `` string as its
@@ -224,7 +224,8 @@ which has been appropriately marked.
224
224
import sys
225
225
from pluggy import PluginManager, HookimplMarker
226
226
227
- hookimpl = HookimplMarker(' myproject' )
227
+ hookimpl = HookimplMarker(" myproject" )
228
+
228
229
229
230
@hookimpl
230
231
def setup_project (config , args ):
@@ -236,7 +237,8 @@ which has been appropriately marked.
236
237
237
238
return config
238
239
239
- pm = PluginManager(' myproject' )
240
+
241
+ pm = PluginManager(" myproject" )
240
242
241
243
# load all hookimpls from the local module's namespace
242
244
plugin_name = pm.register(sys.modules[__name__ ])
@@ -273,7 +275,8 @@ will be executed *first* or *last* respectively in the hook call loop:
273
275
import sys
274
276
from pluggy import PluginManager, HookimplMarker
275
277
276
- hookimpl = HookimplMarker(' myproject' )
278
+ hookimpl = HookimplMarker(" myproject" )
279
+
277
280
278
281
@hookimpl (trylast = True )
279
282
def setup_project (config , args ):
@@ -288,6 +291,7 @@ will be executed *first* or *last* respectively in the hook call loop:
288
291
class SomeOtherPlugin (object ):
289
292
""" Some other plugin defining the same hook.
290
293
"""
294
+
291
295
@hookimpl (tryfirst = True )
292
296
def setup_project (self , config , args ):
293
297
""" Report what args were passed before calling
@@ -298,7 +302,8 @@ will be executed *first* or *last* respectively in the hook call loop:
298
302
299
303
return config
300
304
301
- pm = PluginManager(' myproject' )
305
+
306
+ pm = PluginManager(" myproject" )
302
307
303
308
# load from the local module's namespace
304
309
pm.register(sys.modules[__name__ ])
@@ -334,8 +339,7 @@ be implemented as generator function with a single ``yield`` in its body:
334
339
should return json encoded config options.
335
340
"""
336
341
if config.debug:
337
- print (" Pre-hook config is {} " .format(
338
- config.tojson()))
342
+ print (" Pre-hook config is {} " .format(config.tojson()))
339
343
340
344
# get initial default config
341
345
defaults = config.tojson()
@@ -347,8 +351,7 @@ be implemented as generator function with a single ``yield`` in its body:
347
351
print (" JSON config override is {} " .format(item))
348
352
349
353
if config.debug:
350
- print (" Post-hook config is {} " .format(
351
- config.tojson()))
354
+ print (" Post-hook config is {} " .format(config.tojson()))
352
355
353
356
if config.use_defaults:
354
357
outcome.force_result(defaults)
@@ -387,15 +390,17 @@ should be added before registering corresponding *hookimpls*:
387
390
import sys
388
391
from pluggy import PluginManager, HookspecMarker
389
392
390
- hookspec = HookspecMarker(' myproject' )
393
+ hookspec = HookspecMarker(" myproject" )
394
+
391
395
392
396
@hookspec
393
397
def setup_project (config , args ):
394
398
""" This hook is used to process the initial config and input
395
399
arguments.
396
400
"""
397
401
398
- pm = PluginManager(' myproject' )
402
+
403
+ pm = PluginManager(" myproject" )
399
404
400
405
# load from the local module's namespace
401
406
pm.add_hookspecs(sys.modules[__name__ ])
@@ -437,6 +442,7 @@ In other words this is ok:
437
442
def myhook (config , args ):
438
443
pass
439
444
445
+
440
446
@hookimpl
441
447
def myhook (args ):
442
448
print (args)
@@ -450,6 +456,7 @@ whereas this is not:
450
456
def myhook (config , args ):
451
457
pass
452
458
459
+
453
460
@hookimpl
454
461
def myhook (config , args , extra_arg ):
455
462
print (args)
@@ -513,7 +520,9 @@ if a hookspec specifies a ``warn_on_impl``, pluggy will trigger it for any plugi
513
520
514
521
.. code-block :: python
515
522
516
- @hookspec (warn_on_impl = DeprecationWarning (" oldhook is deprecated and will be removed soon" ))
523
+ @hookspec (
524
+ warn_on_impl = DeprecationWarning (" oldhook is deprecated and will be removed soon" )
525
+ )
517
526
def oldhook ():
518
527
pass
519
528
@@ -530,7 +539,8 @@ A ``PluginManager`` is instantiated with a single
530
539
.. code-block :: python
531
540
532
541
import pluggy
533
- pm = pluggy.PluginManager(' my_project_name' )
542
+
543
+ pm = pluggy.PluginManager(" my_project_name" )
534
544
535
545
536
546
The ``project_name `` value is used when a ``PluginManager `` scans for *hook *
@@ -643,7 +653,8 @@ assertion should not error:
643
653
644
654
from pluggy import PluginManager, HookimplMarker
645
655
646
- hookimpl = HookimplMarker(' myproject' )
656
+ hookimpl = HookimplMarker(" myproject" )
657
+
647
658
648
659
class Plugin1 (object ):
649
660
@hookimpl
@@ -652,21 +663,24 @@ assertion should not error:
652
663
"""
653
664
return 1
654
665
666
+
655
667
class Plugin2 (object ):
656
668
@hookimpl
657
669
def myhook (self , args ):
658
670
""" Default implementation.
659
671
"""
660
672
return 2
661
673
674
+
662
675
class Plugin3 (object ):
663
676
@hookimpl
664
677
def myhook (self , args ):
665
678
""" Default implementation.
666
679
"""
667
680
return 3
668
681
669
- pm = PluginManager(' myproject' )
682
+
683
+ pm = PluginManager(" myproject" )
670
684
pm.register(Plugin1())
671
685
pm.register(Plugin2())
672
686
pm.register(Plugin3())
@@ -697,23 +711,27 @@ point:
697
711
698
712
from pluggy import PluginManager, HookimplMarker
699
713
700
- hookimpl = HookimplMarker(' myproject' )
714
+ hookimpl = HookimplMarker(" myproject" )
715
+
701
716
702
717
class Plugin1 (object ):
703
718
@hookimpl
704
719
def myhook (self , args ):
705
720
return 1
706
721
722
+
707
723
class Plugin2 (object ):
708
724
@hookimpl
709
725
def myhook (self , args ):
710
726
raise RuntimeError
711
727
728
+
712
729
class Plugin3 (object ):
713
730
@hookimpl
714
731
def myhook (self , args ):
715
732
return 3
716
733
734
+
717
735
@hookimpl (hookwrapper = True )
718
736
def myhook (self , args ):
719
737
outcome = yield
@@ -724,7 +742,8 @@ point:
724
742
# log the error details
725
743
print (outcome.excinfo)
726
744
727
- pm = PluginManager(' myproject' )
745
+
746
+ pm = PluginManager(" myproject" )
728
747
729
748
# register plugins
730
749
pm.register(Plugin1())
@@ -752,11 +771,9 @@ using the :py:meth:`pluggy._HookCaller.call_historic()` method:
752
771
def callback (result ):
753
772
print (" historic call result is {result} " .format(result = result))
754
773
774
+
755
775
# call with history; no results returned
756
- pm.hook.myhook.call_historic(
757
- config = config, args = sys.argv,
758
- result_callback = callback
759
- )
776
+ pm.hook.myhook.call_historic(config = config, args = sys.argv, result_callback = callback)
760
777
761
778
# ... more of our program ...
762
779
@@ -813,7 +830,7 @@ undo function to disable the behaviour.
813
830
814
831
.. code-block :: python
815
832
816
- pm = PluginManager(' myproject' )
833
+ pm = PluginManager(" myproject" )
817
834
# magic line to set a writer function
818
835
pm.trace.root.setwriter(print )
819
836
undo = pm.enable_tracing()
@@ -832,6 +849,7 @@ The expected signature and default implementations for these functions is:
832
849
def before (hook_name , methods , kwargs ):
833
850
pass
834
851
852
+
835
853
def after (outcome , hook_name , methods , kwargs ):
836
854
pass
837
855
0 commit comments