Skip to content

Commit 653a1e9

Browse files
committed
Implement the suggestions by @tgoodlet
1 parent 115f1fc commit 653a1e9

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

docs/examples/eggsample-spam/eggsample_spam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def eggsample_add_ingredients(ingredients):
66
ingredients.remove("egg")
77
spam = ["lovely spam", "wonderous spam", "splendiferous spam"]
88
print(f"Add {spam}")
9-
ingredients.extend(spam)
9+
return spam
1010

1111
@eggsample.hookimpl
1212
def eggsample_prep_condiments(condiments):

docs/examples/eggsample/eggsample/host.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
condiments_tray = {"pickled walnuts": 13, "steak sauce": 4, "mushy peas": 2}
88

9-
class EggselentCook:
9+
class EggsellentCook:
1010
def __init__(self, hook):
1111
self.hook = hook
1212
self.ingredients = []
1313

1414
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)
1619

1720
def prepare_the_food(self):
1821
random.shuffle(self.ingredients)
@@ -27,7 +30,7 @@ def main():
2730
pluginmanager.add_hookspecs(hookspecs)
2831
pluginmanager.load_setuptools_entrypoints("eggsample")
2932
pluginmanager.register(lib)
30-
cook = EggselentCook(pluginmanager.hook)
33+
cook = EggsellentCook(pluginmanager.hook)
3134
cook.add_ingredients()
3235
cook.prepare_the_food()
3336
cook.serve_the_food()

docs/examples/eggsample/eggsample/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def eggsample_add_ingredients(ingredients):
55
basics = ["egg", "egg", "salt", "pepper"]
66
print(f"Add {basics}")
7-
ingredients.extend(basics)
7+
return basics
88

99
@eggsample.hookimpl
1010
def eggsample_prep_condiments(condiments):

docs/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ avoid unnecessary exposure of state and behaviour. This leads to a more
3434
between ``host`` and ``plugins``.
3535

3636
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
4040
and objects to work with.
4141

4242
How does it work?
@@ -46,7 +46,7 @@ Let us start with a short overview of what is involved:
4646
* ``host`` or ``host program``: the program offering extensibility
4747
by specifying ``hook functions`` and invoking their implementation(s) as
4848
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
5050
participating in program execution when the implementations are invoked
5151
by the ``host``
5252
* ``pluggy``: connects ``host`` and ``plugins`` by using ...

0 commit comments

Comments
 (0)