🐍 Pluggable Architecture with Python
pytest has open sourced their amazing plugin framework, 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 # 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 # 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 # library author plugin author end user Using a plugin # 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. There are two common ways that I have seen that…