Hi devs,

I am still evolving my GDAPS plugin system for Django (which works well here), and try to overcome some shortcomings of Django that is not really easy so solve, like dynamically added INSTALLED_APPS.

Given the need that a plugin that is installed/found via setuptools/entry point (like GDAPS, or e.g. Pretix does), it can sometimes be necessary that a plugin itself needs another app (like e.g. django-money etc.) as "dependency".

Install-wise this is no problem, as it can be added as "dependency" in setup.py, setup.cfg or, as in my case, pyproject.toml. But to make the main app use that dependency, it must be added to the INSTALLEd_APPS list during the setup process.

I solved that problem by adding a helper function that must be called after INSTALLED_APPS in settings.py, which dynamically imports the plugin class (no models, no views, just the plugin main class itself, e.g. "foo_main_app.plugins.dynamically_added_plugin", and searches for an INSTALLED_APPS attr in that namespace. If it exists, it is basically appended to the main INSTALLED_APPS.

To solve ordering problems, it is a bit more complicated, and the plugin gets the chance to reorder the INSTALLED_APPS and insert its own dependencies (and itself) to a special index.

But basically the main module of the django (plugin) app is imported, and read. This works, but I'd like to ask you if this violates any of Django's principles, or if there would be a better approach in the long term to create pluggable apps, that just can be installed by pip.

The only reason I post it here (in dev) is that this may be of interest too for Django itself at some point in time too. But here I need your feedback.

I first wanted to put that information into the AppConfig class - but can't be loaded in settings.py - apps aren't loaded. So, for my taste, plugin information is a bit scattered around (AppConfig in apps.py, INSTALLED_APPS and more in __init__.py). It could be added declaratively in some yaml file too, but this would feel even creepier to me.

Eager to hear your opinion here.

--
Dr. Christian González
https://nerdocs.at

--
You received this message because you are subscribed to the Google Groups "Django 
developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/af191009-898a-ed99-7d6a-4f99057674fc%40nerdocs.at.

Reply via email to