Skip to content

Commit a20a667

Browse files
committed
Improve the output and make clearer, why we do what we do in docs.
1 parent e84fdfa commit a20a667

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

docs/examples/eggsample-spam/eggsample_spam.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
@eggsample.hookimpl
44
def eggsample_add_ingredients(ingredients):
5-
"""Here we get an immutable object, so we return something to the caller."""
5+
"""Here the caller expects us to return a list."""
66
if "egg" in ingredients:
77
spam = ["lovely spam", "wonderous spam"]
88
else:
99
spam = ["splendiferous spam", "magnificent spam"]
10-
print(f"Add {spam}")
1110
return spam
1211

1312
@eggsample.hookimpl
1413
def eggsample_prep_condiments(condiments):
15-
"""Here we get a mutable object, so we just mess with it directly."""
14+
"""Here the caller passes a mutable object, so we mess with it directly."""
1615
try:
1716
del condiments["steak sauce"]
1817
except KeyError:
1918
pass
2019
condiments['spam sauce'] = 42
21-
print(f"Now. this is what I call a condiments tray!")
20+
return f"Now this is what I call a condiments tray!"

docs/examples/eggsample/eggsample/hookspecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def eggsample_prep_condiments(condiments: dict):
1515
"""Reorganize the condiments tray to your heart's content.
1616
1717
:param condiments: some sauces and stuff
18-
:return: will be ignored by caller
18+
:return: a witty comment about your activity
1919
"""

docs/examples/eggsample/eggsample/host.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ def prepare_the_food(self):
4040
random.shuffle(self.ingredients)
4141

4242
def serve_the_food(self):
43-
self.hook.eggsample_prep_condiments(condiments=condiments_tray)
44-
print(f"Your food: {', '.join(self.ingredients)}")
45-
print(f"Some condiments: {', '.join(condiments_tray.keys())}")
43+
condiment_comments = self.hook.eggsample_prep_condiments(
44+
condiments=condiments_tray)
45+
print(f"Your food. Enjoy some {', '.join(self.ingredients)}")
46+
print(f"Some condiments? We have {', '.join(condiments_tray.keys())}")
47+
if any(condiment_comments):
48+
print("\n".join(condiment_comments))
4649

4750
if __name__ == '__main__':
4851
main()

docs/examples/eggsample/eggsample/lib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def eggsample_add_ingredients():
55
spices = ["salt", "pepper"]
66
you_can_never_have_enough_eggs = ["egg", "egg"]
77
ingredients = spices + you_can_never_have_enough_eggs
8-
print(f"Add {ingredients}")
98
return ingredients
109

1110
@eggsample.hookimpl

docs/index.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ Let's get cooking - we install the host and see what a program run looks like::
127127
$ pip install --editable pluggy/docs/examples/eggsample
128128
$ eggsample
129129

130-
Add ['salt', 'pepper', 'egg', 'egg']
131-
Your food: pepper, egg, egg, egg, egg, salt, egg
132-
Some condiments: pickled walnuts, steak sauce, mushy peas, mint sauce
130+
Your food. Enjoy some egg, egg, salt, egg, egg, pepper, egg
131+
Some condiments? We have pickled walnuts, steak sauce, mushy peas, mint sauce
133132

134133
The plugin
135134
^^^^^^^^^^
@@ -147,11 +146,9 @@ we get::
147146
$ pip install --editable pluggy/docs/examples/eggsample-spam
148147
$ eggsample
149148

150-
Add ['salt', 'pepper', 'egg', 'egg']
151-
Add ['lovely spam', 'wonderous spam']
152-
Now, this is what I call a condiments tray!
153-
Your food: wonderous spam, pepper, egg, egg, egg, egg, lovely spam, egg, salt
154-
Some condiments: pickled walnuts, mushy peas, mint sauce, spam sauce
149+
Your food. Enjoy some egg, lovely spam, salt, egg, egg, egg, wonderous spam, egg, pepper
150+
Some condiments? We have pickled walnuts, mushy peas, mint sauce, spam sauce
151+
Now this is what I call a condiments tray!
155152

156153
More real world examples
157154
------------------------

0 commit comments

Comments
 (0)