File tree Expand file tree Collapse file tree 4 files changed +12
-9
lines changed Expand file tree Collapse file tree 4 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ def eggsample_add_ingredients(ingredients):
6
6
ingredients .remove ("egg" )
7
7
spam = ["lovely spam" , "wonderous spam" , "splendiferous spam" ]
8
8
print (f"Add { spam } " )
9
- ingredients . extend ( spam )
9
+ return spam
10
10
11
11
@eggsample .hookimpl
12
12
def eggsample_prep_condiments (condiments ):
Original file line number Diff line number Diff line change 6
6
7
7
condiments_tray = {"pickled walnuts" : 13 , "steak sauce" : 4 , "mushy peas" : 2 }
8
8
9
- class EggselentCook :
9
+ class EggsellentCook :
10
10
def __init__ (self , hook ):
11
11
self .hook = hook
12
12
self .ingredients = []
13
13
14
14
def add_ingredients (self ):
15
- self .hook .eggsample_add_ingredients (ingredients = self .ingredients )
15
+ more_ingredients = self .hook .eggsample_add_ingredients (
16
+ ingredients = self .ingredients )
17
+ # each hook implementation returned a list of ingredients
18
+ self .ingredients .extend (more_ingredients )
16
19
17
20
def prepare_the_food (self ):
18
21
random .shuffle (self .ingredients )
@@ -27,7 +30,7 @@ def main():
27
30
pluginmanager .add_hookspecs (hookspecs )
28
31
pluginmanager .load_setuptools_entrypoints ("eggsample" )
29
32
pluginmanager .register (lib )
30
- cook = EggselentCook (pluginmanager .hook )
33
+ cook = EggsellentCook (pluginmanager .hook )
31
34
cook .add_ingredients ()
32
35
cook .prepare_the_food ()
33
36
cook .serve_the_food ()
Original file line number Diff line number Diff line change 4
4
def eggsample_add_ingredients (ingredients ):
5
5
basics = ["egg" , "egg" , "salt" , "pepper" ]
6
6
print (f"Add { basics } " )
7
- ingredients . extend ( basics )
7
+ return basics
8
8
9
9
@eggsample .hookimpl
10
10
def eggsample_prep_condiments (condiments ):
Original file line number Diff line number Diff line change @@ -34,9 +34,9 @@ avoid unnecessary exposure of state and behaviour. This leads to a more
34
34
between ``host `` and ``plugins ``.
35
35
36
36
The ``pluggy `` approach puts the burden on the designer of the
37
- ``host program `` to think carefully about which objects are explicitly needed
38
- by an implementation and gives designers of the `` plugin `` a clear framework
39
- for how to extend the ``host `` by giving them a well defined set of functions
37
+ ``host program `` to think carefully about which objects are really
38
+ needed in a hook implementation, which gives ` plugin ` creators a clear
39
+ framework for how to extend the ``host `` via a well defined set of functions
40
40
and objects to work with.
41
41
42
42
How does it work?
@@ -46,7 +46,7 @@ Let us start with a short overview of what is involved:
46
46
* ``host `` or ``host program ``: the program offering extensibility
47
47
by specifying ``hook functions `` and invoking their implementation(s) as
48
48
part of program execution
49
- * ``plugin ``: the program implementing a subset of the specified hooks and
49
+ * ``plugin ``: the program implementing ( a subset of) the specified hooks and
50
50
participating in program execution when the implementations are invoked
51
51
by the ``host ``
52
52
* ``pluggy ``: connects ``host `` and ``plugins `` by using ...
You can’t perform that action at this time.
0 commit comments