hello,

AppConfig could provide hooks, but it'd indeed be already quite late in the 
setup process : settings are already loaded, logging already configured, 
script prefix already set, and just accessing AppConfig could already 
trigger the import of advanced submodules (models etc.), which could break 
the early setup.

I guess an environment variable, or a naming convention, could allow early 
hooks similar to those of Gunicorn for example, and unrelated to installed 
apps.

regards,
Pascal Chambon


On Tuesday, July 2, 2019 at 8:40:04 PM UTC+2, Christian González wrote:
>
>
> Am 01.07.19 um 23:24 schrieb Pkl: 
> > 
> > Regarding django.setup() tweakability, the generic need is simply to 
> > have a hook, somewhere for users to put early init code, regardless of 
> > the way django is launched. Code that needs to execute this early are 
> > mostly (if not all) monkey-patching the environnement, a little like a 
> > LD_PRELOAD logic python-style. 
> > [snip] 
> > There are surely lots of ways to provide such a hook, via new 
> > settings, or new environment variables, or modules following precise 
> > naming conventions that django would systematically try to import... I 
> > have no idea how exactly my approach is rated amongst them. 
> > 
> > As for alternatives to these early setup hooks, I'm alas clueless... 
>
> Why not a setup() method in the Apps' AppConfig, like ready()? This way 
> the AppConfig would be used more. Problem here is: when setup runs, it 
> is loading the settings. And THERE INSTALLED_APPS first time tell Django 
> which apps are installed. So before that point, it's not possible to  
> "import modules from apps following a precise naming convention" etc. Or 
> did you mean "modules" outside of apps like e.g. a 
> "django_hook_setup_foo" python module? (Grrrrrr.) 
>
> Maybe here could again help to extract the apps list out of settings, 
> and use a descriptive list that is parsed VERY early in the setup 
> process. Then the hook could be placed (with imports from all apps). 
>
> This would help improving my GDAPS plugins system as well, instead of 
> hacking myself into INSTALLED_APPS within settings.py. 
>
> Just my 2 cents. 
>
> Christian 
>
>

-- 
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 post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/7a34d34c-0098-4430-b9af-2bf05244755d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to