Allow packaged resources and alternate extensions
bckohan opened this issue · 0 comments
Thanks for a great utility. It's kept my Django settings sane for a few years now.
I manage several large Django projects with many apps that are deployed in multiple settings, each time having a different INSTALLED_APP stack. A pattern I've found immensely useful in this scenario is for my constituent app packages to include default settings files as packaged resources. I give them alternate extensions (i.e. .conf instead of .py) so my system knows which ones to automagically include.
I've been using an extended version of django-split-settings to accomplish this, but I think others could find this useful as well so I'm happy to submit my extensions as a PR.
For example, the idea is to be able to include packaged resources where your directory structure looks like:
mypackage
├── __init__.py
└── settings
├── __init__.py
└── base.conf
As so:
from split_settings import include, resource, optional
from mypackage import settings
include(
resource(settings, 'base.conf'),
resource('mypackage.settings', 'base.conf'), # alternate
optional(resource(settings, 'local.conf')), # optional can wrap resources too
)
Another nicety about using an alternate to .py for your settings files is that its a visual cue to other devs (and your IDE) that these files may not behave like typical python files on account of how split-settings sets their scope.