Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peopledoc/django-compose-settings
Django composable settings loader.
https://github.com/peopledoc/django-compose-settings
approved-public ghec-mig-migrated
Last synced: 17 days ago
JSON representation
Django composable settings loader.
- Host: GitHub
- URL: https://github.com/peopledoc/django-compose-settings
- Owner: peopledoc
- License: mit
- Created: 2015-11-19T14:00:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-18T14:32:10.000Z (almost 3 years ago)
- Last Synced: 2024-12-08T20:51:12.807Z (25 days ago)
- Topics: approved-public, ghec-mig-migrated
- Language: Python
- Homepage:
- Size: 26.4 KB
- Stars: 6
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
=================================
Django composable settings loader
=================================.. image:: https://circleci.com/gh/novafloss/django-compose-settings.svg?style=shield
:target: https://circleci.com/gh/novafloss/django-compose-settings
:alt: We are under CI!!Aims to compose your settings from python modules and python scripts in /etc.
In your ``my_app/settings/__init__.py`` call the loader::
from django_compose_settings import modules_loader
locals().update(modules_loader(prefix='my_app', default='base,etc,post'))
In ``my_app/settings/base.py`` define default values as usual, ex::
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# ...
In ``my_app/settings/etc.py`` call the etc loader::
from django_compose_settings import etc_loader
locals().update(etc_loader(prefix='my_app'))
You can validate settings in ``my_app/settings/post.py`` as follow::
import __settings__
assert hasattr(__settings__, 'BASE_DIR'), 'BASE_DIR required'
Etc settings
============Here is a sample tree of your ``/etc/my_app``::
/etc/my_app/
├── settings.d
│ ├── 00_prod1.py
│ └── 99_local.py
└── settings.pyEach ``.py`` file is a regular *composable* settings file as ``post.py`` above.
MY_APP_SETTINGS
===============You can override your settings with a specific SETTINGS environment variable
for your app as follow::$ MY_APP_SETTINGS=base,post python
>>> import logging
>>> logging.basicConfig(
... level=logging.INFO,
... format='%(asctime)s %(levelname)-8s %(name)s %(message)s'
... )>>> import os
>>> import sys
>>> sys.path.append(os.path.join(os.path.abspath('tests'), 'fixtures'))>>> from my_app import settings
2015-11-23 10:59:09,964 INFO django_compose_settings Loaded my_app.settings.base
2015-11-23 10:59:09,964 INFO django_compose_settings Loaded my_app.settings.post