Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Registering new Datasette plugin hooks by defining them in other plugins#
I’m experimenting with a Datasette plugin that itself adds new plugin hooks which other plugins can then interact with.
It’s called datasette-low-disk-space-hook, and it adds a new plugin hook called low_disk_space(datasette), defined in the datasette_low_disk_space_hook/hookspecs.py module.
The hook is registered by this code in datasette_low_disk_space_hook/__init__.py
1from datasette.utils import await_me_maybe2from datasette.plugins import pm3from . import hookspecs4
5pm.add_hookspecs(hookspecs)This imports the plugin manager directly from Datasette and uses it to add the new hooks.
I was worried that the pm.add_hookspects(hookspecs) line was not guaranteed to be executed if that module had not been imported.
It turns out that having this entrpoints= line in setup.py is enough to ensure that the module is imported and the pm.add_hookspecs() line is executed:
1from setuptools import setup2
3setup(4 name="datasette-low-disk-space-hook",5 # ...6 entry_points={"datasette": ["low_disk_space_hook = datasette_low_disk_space_hook"]},7 # ...8)