|
| 1 | +pluggy - A minimalist production ready plugin system |
| 2 | +==================================================== |
| 3 | +|pypi| |versions| |travis| |appveyor| |
1 | 4 |
|
2 |
| -Plugin registration and hook calling for Python |
3 |
| -=============================================== |
4 | 5 |
|
5 |
| -.. image:: https://img.shields.io/pypi/v/pluggy.svg |
| 6 | +This is the core framework used by the `pytest`_, `tox`_, and `devpi`_ projects. |
| 7 | + |
| 8 | +Please `read the docs`_ to learn more! |
| 9 | + |
| 10 | +A definitive example |
| 11 | +******************** |
| 12 | +.. code-block:: python |
| 13 | +
|
| 14 | + import pluggy |
| 15 | +
|
| 16 | + hookspec = pluggy.HookspecMarker("myproject") |
| 17 | + hookimpl = pluggy.HookimplMarker("myproject") |
| 18 | +
|
| 19 | +
|
| 20 | + class MySpec(object): |
| 21 | + """A hook specification namespace. |
| 22 | + """ |
| 23 | + @hookspec |
| 24 | + def myhook(self, arg1, arg2): |
| 25 | + """My special little hook that you can customize. |
| 26 | + """ |
| 27 | +
|
| 28 | +
|
| 29 | + class Plugin_1(object): |
| 30 | + """A hook implementation namespace. |
| 31 | + """ |
| 32 | + @hookimpl |
| 33 | + def myhook(self, arg1, arg2): |
| 34 | + print("inside Plugin_1.myhook()") |
| 35 | + return arg1 + arg2 |
| 36 | +
|
| 37 | +
|
| 38 | + class Plugin_2(object): |
| 39 | + """A 2nd hook implementation namespace. |
| 40 | + """ |
| 41 | + @hookimpl |
| 42 | + def myhook(self, arg1, arg2): |
| 43 | + print("inside Plugin_2.myhook()") |
| 44 | + return arg1 - arg2 |
| 45 | +
|
| 46 | +
|
| 47 | + # create a manager and add the spec |
| 48 | + pm = pluggy.PluginManager("myproject") |
| 49 | + pm.add_hookspecs(MySpec) |
| 50 | +
|
| 51 | + # register plugins |
| 52 | + pm.register(Plugin_1()) |
| 53 | + pm.register(Plugin_2()) |
| 54 | +
|
| 55 | + # call our `myhook` hook |
| 56 | + results = pm.hook.myhook(arg1=1, arg2=2) |
| 57 | + print(results) |
| 58 | +
|
| 59 | +
|
| 60 | +.. badges |
| 61 | +.. |pypi| image:: https://img.shields.io/pypi/v/pluggy.svg |
6 | 62 | :target: https://pypi.python.org/pypi/pluggy
|
7 |
| -.. image:: https://img.shields.io/pypi/pyversions/pluggy.svg |
| 63 | +.. |versions| image:: https://img.shields.io/pypi/pyversions/pluggy.svg |
8 | 64 | :target: https://pypi.python.org/pypi/pluggy
|
9 |
| -.. image:: https://img.shields.io/travis/pytest-dev/pluggy/master.svg |
| 65 | +.. |travis| image:: https://img.shields.io/travis/pytest-dev/pluggy/master.svg |
10 | 66 | :target: https://travis-ci.org/pytest-dev/pluggy
|
11 |
| -.. image:: https://img.shields.io/appveyor/ci/pytestbot/pluggy/master.svg |
| 67 | +.. |appveyor| image:: https://img.shields.io/appveyor/ci/pytestbot/pluggy/master.svg |
12 | 68 | :target: https://ci.appveyor.com/project/pytestbot/pluggy
|
13 | 69 |
|
14 |
| -This is the core plugin system used by the `pytest`_, `tox`_, and `devpi`_ projects. |
15 |
| -Please `read the docs`_ to learn more! |
16 |
| - |
17 | 70 | .. links
|
18 | 71 | .. _pytest:
|
19 | 72 | http://pytest.org
|
|
0 commit comments