It's an interesting idea, and I'm not opposed to it myself; however, keeping 
the settings as Python code is not an abnormal practice compared to other 
software.

I've been working with some Drupal stuff lately, and it is written in PHP. 
Drupal is a content management system that can be extended with various modules 
written in PHP. It's settings file is also just a code file of PHP. Drupal does 
take advantage of a package manger called composer, which would be similar to 
our pipenv. Both of those managers use JSON files for their appropriate 
settings. But package managers are not frameworks.

Perhaps we could set up a hybrid in which we have a declarative settings file 
that can be utilized by a coded settings file, but I feel that might make the 
whole system a bit too complex to maintain.

Just my thoughts.

-----Original Message-----
From: django-developers@googlegroups.com 
[mailto:django-developers@googlegroups.com] On Behalf Of Christian González
Sent: Monday, December 30, 2019 4:46 PM
To: django-developers
Subject: declarative settings

Hello,

I recently "finished" my first really working version of GDAPS, my Generic 
Django Application Plugin System. It's noway perfect, but does what it should: 
providing pluggable apps for an app framework, including a more or less 
flexible frontend with each django app.

I had much struggle with it, and one of the lessons I learned was Django's 
setup system, and how it deals with loading apps. Unfortunately Django can't 
load/unload apps on the fly, so it is necessary to restart Django whenever a 
new GDAPS app is installed via pip.

But: I want to resurrect an old theme again which would, in a way, improve some 
of the loading problems I encountered. Django's settings are code. Which is, in 
fact, a very good thing, as it makes it extremely flexible and adaptable to 
different setups. But, as discussed with the SECRET_KEY here, some of the 
settings _have_ to be coded very complicated, and it makes some things like 
per-app-settings extremely uncomfortable.

What if - and please don't kill me instantly - yes, I am a newcomer, and not a 
good programmer maybe - but some things are viewed better from "outside" - what 
if Django settings could be "declarative"?

So instead of Python code like

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes'
]

This would be in an e.g. JSON file

{

    "INSTALLED_APPS": [
        "django.contrib.admin",
        "django.contrib.auth",
        "django.contrib.contenttypes"
    ] ,
    ROOT_URLCONF: "fooproject.urls"
}

Django's settings.py would look different: It would load that settings.json 
file and set the appropriate values into local code - so this wouldn't make 
much difference.

Except 2 things:

1. Apps could have (default) settings, and they could be merged MUCH easier. 
Things like namespaced classes that are overwriting values like DRF/graphene 
does, would be completely unnecessary. The main settings.json file could be the 
"last word" in the process of settings, so anything an app would suggest could 
be overrided in the main file.

2. Installed apps could be managed much more comfortable. Adding an app could 
be done by a script (JSON editing is easy. Editing code
(=settings.py) is error prone and uncomfortable). I have a Django command 
script ATM for that, but just because I add a line into settings.py to add some 
additional apps to the list.

This even could be done with backwards compatibility, because Django would keep 
it's settings.py file optionally:

* read json settings (if they exist), use them
* load settings.py which allows to override them again (using some special code 
tricks like dynamic loading, environments etc.)

Please tell me what you think about that.

Christian


--
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/3047a7b6-3fa0-d574-4bb6-7842b7aed44a%40nerdocs.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/8ea6a5cda5f64ff6babaaf3e42fa9629%40iss2.ISS.LOCAL.

Reply via email to