Skip to content

Commit c2286a9

Browse files
committed
work in fixes, suggestions from review
* fix typos * use pluginmanager in a fashion closer to real world usage * normalize whitespace after titles in docs
1 parent ffe2caa commit c2286a9

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

docs/examples/eggsample-spam/eggsample_spam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def eggsample_add_ingredients(ingredients):
55
if len([e for e in ingredients if e == "egg"]) > 2:
66
ingredients.remove("egg")
77
spam = ["lovely spam", "wonderous spam", "splendiferous spam"]
8-
print(f"add {spam}")
8+
print(f"Add {spam}")
99
ingredients.extend(spam)
1010

1111
@eggsample.hookimpl
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import pluggy
22

33
hookimpl = pluggy.HookimplMarker("eggsample")
4-
"""Marker to be imported and used in plugins"""
5-
6-
pm = pluggy.PluginManager("eggsample")
7-
"""The manager ... you know? to manage the plugins!"""
4+
"""Marker to be imported and used in plugins (and for own implementations)"""

docs/examples/eggsample/eggsample/host.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
import random
22

3-
from eggsample import hookimpl, hookspecs, lib, pm
3+
import pluggy
4+
5+
from eggsample import hookspecs, lib
46

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

7-
class FoodMaster2000:
8-
def __init__(self):
9+
class EggselentCook:
10+
def __init__(self, hook):
11+
self.hook = hook
912
self.ingredients = []
1013

1114
def add_ingredients(self):
12-
pm.hook.eggsample_add_ingredients(ingredients=self.ingredients)
15+
self.hook.eggsample_add_ingredients(ingredients=self.ingredients)
1316

1417
def prepare_the_food(self):
1518
random.shuffle(self.ingredients)
1619

1720
def serve_the_food(self):
18-
pm.hook.eggsample_prep_condiments(condiments=condiments_tray)
21+
self.hook.eggsample_prep_condiments(condiments=condiments_tray)
1922
print(f"Your food: {', '.join(self.ingredients)}")
2023
print(f"Some condiments: {', '.join(condiments_tray.keys())}")
2124

2225
def main():
23-
pm.add_hookspecs(hookspecs)
24-
pm.load_setuptools_entrypoints("eggsample")
25-
pm.register(lib)
26-
fm2000 = FoodMaster2000()
26+
pluginmanager = pluggy.PluginManager("eggsample")
27+
pluginmanager.add_hookspecs(hookspecs)
28+
pluginmanager.load_setuptools_entrypoints("eggsample")
29+
pluginmanager.register(lib)
30+
fm2000 = EggselentCook(pluginmanager.hook)
2731
fm2000.add_ingredients()
2832
fm2000.prepare_the_food()
2933
fm2000.serve_the_food()

docs/index.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ In essence, ``pluggy`` enables function `hooking`_ so you can build
1919

2020
Why is it useful?
2121
*****************
22-
2322
There are some established mechanisms for modifying the behavior of other
2423
programs/libraries in Python like
2524
`method overriding <https://en.wikipedia.org/wiki/Method_overriding>`_
@@ -41,7 +40,6 @@ and objects to work with.
4140

4241
How does it work?
4342
*****************
44-
4543
Let us start with a short overview of what is involved:
4644

4745
* ``host`` or ``host program``: the program offering extensibility
@@ -57,7 +55,7 @@ Let us start with a short overview of what is involved:
5755
- the hook :ref:`implementations <impls>` provided by registered
5856
``plugins`` (a.k.a ``hookimpl`` - see `callbacks`_)
5957
- the hook :ref:`caller <calling>` - a call loop triggered at appropriate
60-
program positions in the ``host`` invoking the implementations
58+
program positions in the ``host`` invoking the implementations and
6159
collecting the results
6260

6361
... where for each registered hook *specification*, a hook *call* will
@@ -98,7 +96,7 @@ the steak sauce from the condiments tray (nobody likes that anyway).
9896
.. note::
9997

10098
**naming markers**: ``HookSpecMarker`` and ``HookImplMarker`` must be
101-
the initialized with the name of the ``host`` project (the ``name``
99+
initialized with the name of the ``host`` project (the ``name``
102100
parameter in ``setup()``) - so **eggsample** in our case.
103101

104102
**naming plugin projects**: they should be named in the form of
@@ -132,7 +130,6 @@ Let's get cooking - we install the host and see what a program run looks like::
132130
Your food: egg, salt, pepper, egg
133131
Some condiments: pickled walnuts, steak sauce, mushy peas, mint sauce
134132

135-
136133
The plugin
137134
^^^^^^^^^^
138135
``eggsample-spam/eggsample_spam.py``
@@ -156,7 +153,6 @@ we get::
156153

157154
More real world examples
158155
------------------------
159-
160156
To see how ``pluggy`` is used in the real world, have a look at these projects
161157
documentation and source code:
162158

0 commit comments

Comments
 (0)