🐍 Pluggable Architecture with Python
pytest has open sourced their amazing plugin framework pluggy, it allows
library authors to give their users a way to modify the libaries behavior
without needing to submit a change that may not make sense to the entire
library.
Previous Experience # [1]
My experience so far as a plugin user, and plugin author has been great.
Building and using plugins are incredibly intuitive. I wanted to dive a bit
deeper and see how they are implemented inside of a library and its a bit of a
mind bend the first time you try to do it.
Plugins vs. Hooks # [2]
A hook is a single function that has a specific place that it is ran by the PluginManager.
A Plugin is a collection of one or more hooks.
Layers # [3]
- library author
- plugin author
- end user
Using a plugin # [4]
For a plugin to be registered is must be registered by the PluginManager which
is implemented by the library author. It is the job of the library author to
determine what plugins are actively registered or disabled. Ther...