Skip to content

Commit 9faa0ba

Browse files
author
Tyler Goodlet
committed
README improvements
Some simple fix ups as per #47. Resolves #47
1 parent 9b2bc8c commit 9faa0ba

File tree

1 file changed

+62
-9
lines changed

1 file changed

+62
-9
lines changed

README.rst

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,72 @@
1+
pluggy - A minimalist production ready plugin system
2+
====================================================
3+
|pypi| |versions| |travis| |appveyor|
14

2-
Plugin registration and hook calling for Python
3-
===============================================
45

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
662
: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
864
: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
1066
: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
1268
:target: https://ci.appveyor.com/project/pytestbot/pluggy
1369

14-
This is the core plugin system used by the `pytest`_, `tox`_, and `devpi`_ projects.
15-
Please `read the docs`_ to learn more!
16-
1770
.. links
1871
.. _pytest:
1972
http://pytest.org

0 commit comments

Comments
 (0)