simonw / djp

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

./manage.py showplugins command #5

Closed simonw closed 2 months ago

simonw commented 2 months ago

Imitating showmigrations. Lists migrations, like datasette plugins and llm plugins do.

simonw commented 2 months ago

Here's the LLM implementation: https://github.com/simonw/llm/blob/d654c9521235a737e59a4f1d77cf4682589123ec/llm/__init__.py#L44-L61

def get_plugins(all=False):
    plugins = []
    plugin_to_distinfo = dict(pm.list_plugin_distinfo())
    for plugin in pm.get_plugins():
        if not all and plugin.__name__.startswith("llm.default_plugins."):
            continue
        plugin_info = {
            "name": plugin.__name__,
            "hooks": [h.name for h in pm.get_hookcallers(plugin)],
        }
        distinfo = plugin_to_distinfo.get(plugin)
        if distinfo:
            plugin_info["version"] = distinfo.version
            plugin_info["name"] = (
                getattr(distinfo, "name", None) or distinfo.project_name
            )
        plugins.append(plugin_info)
    return plugins
simonw commented 2 months ago

Example output:

./manage.py showplugins
[
  {
    "name": "django-plugin-blog",
    "hooks": [
      "installed_apps",
      "middleware",
      "settings",
      "urlpatterns"
    ],
    "version": "0.1"
  },
  {
    "name": "django-plugin-django-header",
    "hooks": [
      "middleware"
    ],
    "version": "0.1"
  }
]