simonw / djp

A plugin system for Django
https://djp.readthedocs.io
Apache License 2.0
25 stars 0 forks source link

Initial design #1

Closed simonw closed 2 days ago

simonw commented 2 days ago

Creating this in advance of my DjangoCon US 2024 talk on Tuesday September 24th.

simonw commented 2 days ago

I'm going to start by letting plugins modify INSTALLED_APPS and MIDDLEWARE and urlpatterns.

simonw commented 2 days ago

... and do anything they like to settings.py generally.

simonw commented 2 days ago

Initial plugin hook specs:

from pluggy import HookimplMarker
from pluggy import HookspecMarker

hookspec = HookspecMarker("django_plugins")
hookimpl = HookimplMarker("django_plugins")

@hookspec
def installed_apps():
    """Return a list of Django app strings to be added to INSTALLED_APPS"""

@hookspec
def middleware():
    """
    Return a list of Django middleware class strings to be added to MIDDLEWARE.
    Optionally wrap with django_plugins.Before() or .After() to specify ordering
    """

@hookspec
def urlpatterns():
    """Return a list of url patterns to be added to urlpatterns"""

@hookspec
def settings(current_settings):
    """Modify current_settings in place to finish configuring settings.py"""
simonw commented 2 days ago

I built https://github.com/simonw/docs so I could start the documentation.

simonw commented 2 days ago

Some example plugins: