Debian Codegraph @

testing/web-platform/tests/tools/third_party/pluggy/README.rst

raw
1 ====================================================
2 pluggy - A minimalist production ready plugin system
3 ====================================================
4
5 |pypi| |conda-forge| |versions| |github-actions| |gitter| |black| |codecov|
6
7 This is the core framework used by the `pytest`_, `tox`_, and `devpi`_ projects.
8
9 Please `read the docs`_ to learn more!
10
11 A definitive example
12 ====================
13 .. code-block:: python
14
15 import pluggy
16
17 hookspec = pluggy.HookspecMarker("myproject")
18 hookimpl = pluggy.HookimplMarker("myproject")
19
20
21 class MySpec:
22 """A hook specification namespace."""
23
24 @hookspec
25 def myhook(self, arg1, arg2):
26 """My special little hook that you can customize."""
27
28
29 class Plugin_1:
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:
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 Running this directly gets us::
61
62 $ python docs/examples/toy-example.py
63 inside Plugin_2.myhook()
64 inside Plugin_1.myhook()
65 [-1, 3]
66
67
68 .. badges
69
70 .. |pypi| image:: https://img.shields.io/pypi/v/pluggy.svg
71 :target: https://pypi.org/pypi/pluggy
72
73 .. |versions| image:: https://img.shields.io/pypi/pyversions/pluggy.svg
74 :target: https://pypi.org/pypi/pluggy
75
76 .. |github-actions| image:: https://github.com/pytest-dev/pluggy/workflows/main/badge.svg
77 :target: https://github.com/pytest-dev/pluggy/actions
78
79 .. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pluggy.svg
80 :target: https://anaconda.org/conda-forge/pytest
81
82 .. |gitter| image:: https://badges.gitter.im/pytest-dev/pluggy.svg
83 :alt: Join the chat at https://gitter.im/pytest-dev/pluggy
84 :target: https://gitter.im/pytest-dev/pluggy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
85
86 .. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
87 :target: https://github.com/ambv/black
88
89 .. |codecov| image:: https://codecov.io/gh/pytest-dev/pluggy/branch/master/graph/badge.svg
90 :target: https://codecov.io/gh/pytest-dev/pluggy
91 :alt: Code coverage Status
92
93 .. links
94 .. _pytest:
95 http://pytest.org
96 .. _tox:
97 https://tox.readthedocs.org
98 .. _devpi:
99 http://doc.devpi.net
100 .. _read the docs:
101 https://pluggy.readthedocs.io/en/latest/
102
103
104 Support pluggy
105 --------------
106
107 `Open Collective`_ is an online funding platform for open and transparent communities.
108 It provides tools to raise money and share your finances in full transparency.
109
110 It is the platform of choice for individuals and companies that want to make one-time or
111 monthly donations directly to the project.
112
113 ``pluggy`` is part of the ``pytest-dev`` project, see more details in the `pytest collective`_.
114
115 .. _Open Collective: https://opencollective.com
116 .. _pytest collective: https://opencollective.com/pytest