plugin and hook calling mechanisms for python
Project description
This is the core framework used by the pytest, tox, and devpi projects.
Please read the docs to learn more!
A definitive example
import pluggy
hookspec = pluggy.HookspecMarker("myproject")
hookimpl = pluggy.HookimplMarker("myproject")
class MySpec:
"""A hook specification namespace."""
@hookspec
def myhook(self, arg1, arg2):
"""My special little hook that you can customize."""
class Plugin_1:
"""A hook implementation namespace."""
@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_1.myhook()")
return arg1 + arg2
class Plugin_2:
"""A 2nd hook implementation namespace."""
@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_2.myhook()")
return arg1 - arg2
# create a manager and add the spec
pm = pluggy.PluginManager("myproject")
pm.add_hookspecs(MySpec)
# register plugins
pm.register(Plugin_1())
pm.register(Plugin_2())
# call our ``myhook`` hook
results = pm.hook.myhook(arg1=1, arg2=2)
print(results)
Running this directly gets us:
$ python docs/examples/toy-example.py inside Plugin_2.myhook() inside Plugin_1.myhook() [-1, 3]
Support pluggy
Open Collective is an online funding platform for open and transparent communities. It provides tools to raise money and share your finances in full transparency.
It is the platform of choice for individuals and companies that want to make one-time or monthly donations directly to the project.
pluggy is part of the pytest-dev project, see more details in the pytest collective.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pluggy-1.5.0.tar.gz
.
File metadata
- Download URL: pluggy-1.5.0.tar.gz
- Upload date:
- Size: 68.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1 |
|
MD5 | ac0870be78ba0ee227a5c3955efeba59 |
|
BLAKE2b-256 | 962d02d4312c973c6050a18b314a5ad0b3210edb65a906f868e31c111dede4a6 |
File details
Details for the file pluggy-1.5.0-py3-none-any.whl
.
File metadata
- Download URL: pluggy-1.5.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669 |
|
MD5 | 07349a98333a31cbb6ef8f7a17905c77 |
|
BLAKE2b-256 | 885fe351af9a41f866ac3f1fac4ca0613908d9a41741cfcf2228f4ad853b697d |