matthewwithanm / django-classbasedsettings Goto Github PK
View Code? Open in Web Editor NEWClass based settings. You couldn't get that from the title?
License: MIT License
Class based settings. You couldn't get that from the title?
License: MIT License
Using settings.configure, etc. Is there any way to avoid the two env vars without magic?
Currently, settings classes can only be registered once. (An error is thrown if you register the same one twice.) However, this makes OR'ing rules needlessly difficult. If we relax this, it should be easier.
switcher.register(SettingsA, lambda: 'monkey' in __file__, lambda: 'dog' not in __file__)
switcher.register(SettingsA, lambda: 'monkey' not in __file__, lambda: 'dog' in __file__)
To accommodate this, we'll also have to change the internal representation from a SortedDict to a list so that effects of previous calls to register()
aren't overridden.
Is there a known way with making this work with celery when integrated with Django?
django-configurations seems to have a workaround, but when I try something similar, I think I'm getting circular import problems. Still trying to track it down ...
Don't hardcode 'DJANGO_SETTINGS_MODULE'.
class A(AppSettings):
pass
class P(PrefixedSettings):
pass
class MySettings(A, P):
pass
causes the following error:
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Then auto-register in the base class. Iterate over the registered classes instead of over the module.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/var/virtualenvs/topoftherocknyc.com/lib/python2.5/site-packages/cbsettings/__init__.py", line 9
from .version import *
SyntaxError: 'import *' not allowed with 'from .'
To be used if none match. The mechanism we use will probably depend on what we decide for registration. Possibilities include the following:
class MySettings(object):
SOME_SETTING = 'whatever'
class Meta:
default = True
@register(default=True)
class MySettings(object):
SOME_SETTING = 'whatever'
I'm having an odd problem -- my hiearchy is:
DjangoDefaults -> Base -> Dev -> myDev
DATABASES
appears to reflect Dev not myDev.
When debugging,
ipdb> from django.conf import settings
ipdb> settings
<LazySettings "xxxx.config.factory_factory_unrolledcbsettings">
settings has DATABASES
from Dev.
But if I look at xxxx.config.switcher_switcher_unrolledcbsettings
I get the right DATABASES
.
....but why is one path switcher_switcher
and the other factory_factory
?
I have a switcher module, which just does:
switcher.register(rich.TestingSettings, hostnames=rich.HOSTNAMES, testing=True)
switcher.register(rich.RichDevelopmentSettings, hostnames=rich.HOSTNAMES, testing=False)
manage.py does:
c = switcher()
print("Settings: %s.%s" % (c.__module__, c.__class__.__name__))
cbsettings.configure('xxxx.config.switcher.switcher')
execute_from_command_line(sys.argv)
I commented out my manual call to switcher() above and no difference.
Any ideas?
Django 1.7 deprecated django.utils.importlib and Django 1.9 dropped it.
Traceback (most recent call last):
File "manage.py", line 5, in <module>
import cbsettings
File "/home/vagrant/.virtualenvs/flamingo/local/lib/python2.7/site-packages/cbsettings/__init__.py", line 2, in <module>
from django.utils.importlib import import_module
ImportError: No module named importlib
I'm about to shoot you a pull request.
I think classbasedsettings are great.
I would like to use them in other (non django) projects, too.
Is this possible?
Currently, you have to do this:
switcher.register(MySettings, lambda: 'goforit' in __file__)
Let's make it so you can do this:
switcher.register(MySettings, 'goforit' in __file__)
In other words, check if the simple check is a callable before calling it. Simple!
…instead of adding them to the singleton instance.
FOO=Class is a callable ... so Class gets called and instantiated into an object even though I really want the class instead.
Is there a workaround? Do I just need to make a lambda that returns the class?
Somehow it thinks these are both defined:
django.core.exceptions.ImproperlyConfigured: PASSWORD_RESET_TIMEOUT_DAYS/PASSWORD_RESET_TIMEOUT are mutually exclusive.
And neither are in my code. I even tried setting one to None. I fear that Django has significantly changed their settings module so that there is a conflict now...
Simple checks (the *args
to switcher.register()
) need to be documented in the README.
Hello there!
I'm having trouble running a project under gunicorn. It runs fine with manage.py runserver, but it breaks when I run gunicorn (Django==1.3.7, cbsettings==1.2.1).
Here's the full traceback:
013-05-20 23:27:00 [942] [INFO] Starting gunicorn 0.17.2
2013-05-20 23:27:00 [942] [INFO] Listening at: http://127.0.0.1:8000 (942)
2013-05-20 23:27:00 [942] [INFO] Using worker: sync
2013-05-20 23:27:00 [946] [INFO] Booting worker with pid: 946
2013-05-20 23:27:01 [946] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
worker.init_process()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/base.py", line 103, in wsgi
self.callable = self.load()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/djangoapp.py", line 133, in load
return mod.make_command_wsgi_application(self.admin_media_path)
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
reload_django_settings()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/django_wsgi.py", line 54, in reload_django_settings
reload(mod)
ImportError: No module named settings_factory_unrolledcbsettings
Traceback (most recent call last):
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
worker.init_process()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/base.py", line 103, in wsgi
self.callable = self.load()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/djangoapp.py", line 133, in load
return mod.make_command_wsgi_application(self.admin_media_path)
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
reload_django_settings()
File "/Users/rlander/.virtualenvs/myapp/lib/python2.6/site-packages/gunicorn/app/django_wsgi.py", line 54, in reload_django_settings
reload(mod)
ImportError: No module named settings_factory_unrolledcbsettings
Class Based Settings circumvents Django's settings class which sets Timezone and logger config.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.