|
| 1 | +# Plugins |
| 2 | + |
| 3 | +django-bird uses a plugin system based on [pluggy](https://pluggy.readthedocs.io/) to allow extending its functionality. |
| 4 | + |
| 5 | +## Available Hooks |
| 6 | + |
| 7 | +<!-- [[[cog |
| 8 | +from django.conf import settings |
| 9 | +
|
| 10 | +settings.configure(INSTALLED_APPS=["django_bird"]) |
| 11 | +
|
| 12 | +import cog |
| 13 | +import inspect |
| 14 | +from django_bird.plugins import hookspecs |
| 15 | +from typing import get_type_hints |
| 16 | +
|
| 17 | +hook_functions = [ |
| 18 | + obj for name, obj in inspect.getmembers(hookspecs) |
| 19 | + if inspect.isfunction(obj) and obj.__module__ == 'django_bird.plugins.hookspecs' |
| 20 | +] |
| 21 | +
|
| 22 | +for func in hook_functions: |
| 23 | + hints = get_type_hints(func) |
| 24 | +
|
| 25 | + params = [] |
| 26 | + for name, hint in hints.items(): |
| 27 | + if name != 'return': |
| 28 | + params.append(f"{name}: {hint.__module__}.{hint.__name__}") |
| 29 | +
|
| 30 | + return_type = hints['return'] |
| 31 | +
|
| 32 | + full_sig = f"{func.__name__}({', '.join(params)}) -> {return_type}" |
| 33 | +
|
| 34 | + cog.outl(f"````{{py:function}} {full_sig}") |
| 35 | + cog.outl(f":canonical: django_bird.plugins.hookspecs.{func.__name__}\n") |
| 36 | +
|
| 37 | + if func.__doc__: |
| 38 | + cog.outl(f"```{{autodoc2-docstring}} django_bird.plugins.hookspecs.{func.__name__}") |
| 39 | + cog.outl(":parser: myst") |
| 40 | + cog.outl("```") |
| 41 | +
|
| 42 | + cog.outl("````\n") |
| 43 | +# ]]] --> |
| 44 | +````{py:function} collect_component_assets(template_path: pathlib.Path) -> collections.abc.Iterable[django_bird.staticfiles.Asset] |
| 45 | +:canonical: django_bird.plugins.hookspecs.collect_component_assets |
| 46 | +
|
| 47 | +```{autodoc2-docstring} django_bird.plugins.hookspecs.collect_component_assets |
| 48 | +:parser: myst |
| 49 | +``` |
| 50 | +```` |
| 51 | + |
| 52 | +<!-- [[[end]]] --> |
| 53 | + |
| 54 | +## Creating a Plugin |
| 55 | + |
| 56 | +To create a plugin: |
| 57 | + |
| 58 | +1. Create a Python package for your plugin |
| 59 | +2. Import the `django_bird.hookimpl` marker: |
| 60 | + |
| 61 | + ```python |
| 62 | + from django_bird import hookimpl |
| 63 | + ``` |
| 64 | + |
| 65 | +3. Implement one or more hooks using the `@hookimpl` decorator. |
| 66 | +4. Register your plugin in your package's entry points: |
| 67 | + |
| 68 | + ```toml |
| 69 | + [project.entry-points."django_bird"] |
| 70 | + my_plugin = "my_plugin.module" |
| 71 | + ``` |
| 72 | + |
| 73 | +See the [pluggy documentation](https://pluggy.readthedocs.io/) for more details. |
0 commit comments