From 2877b66982e3562d27c0cc5a70b3f55dc0e88f27 Mon Sep 17 00:00:00 2001 From: Michael van Tellingen Date: Wed, 30 Jan 2013 19:41:40 +0100 Subject: [PATCH 1/2] Initial fixes for python 3 support --- .travis.yml | 3 ++- configurations/base.py | 7 ++++--- configurations/importer.py | 4 ++-- setup.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7dd0167..0dfa9fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: python python: - - "2.5" - "2.6" - "2.7" + - "3.3" before_install: - export PIP_USE_MIRRORS=true - export PIP_INDEX_URL=https://simple.crate.io/ @@ -14,3 +14,4 @@ script: env: - DJANGO=1.3.3 - DJANGO=1.4.1 + - DJANGO=1.5rc1 diff --git a/configurations/base.py b/configurations/base.py index a1f262d..4e4fbf8 100644 --- a/configurations/base.py +++ b/configurations/base.py @@ -1,3 +1,4 @@ +import six from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured @@ -15,7 +16,7 @@ install_failure = ("django-configurations settings importer wasn't " class SettingsBase(type): def __new__(cls, name, bases, attrs): - if bases != (object,): + if bases != (object,) and bases[0].__name__ != 'NewBase': # if this is actually a subclass in a settings module # we better check if the importer was correctly installed from . import importer @@ -33,7 +34,7 @@ class SettingsBase(type): return "" % (self.__module__, self.__name__) -class Settings(object): +class Settings(six.with_metaclass(SettingsBase)): """ The base configuration class to inherit from. @@ -57,4 +58,4 @@ class Settings(object): to the name of the class. """ - __metaclass__ = SettingsBase + pass diff --git a/configurations/importer.py b/configurations/importer.py index 6933eca..43a6e84 100644 --- a/configurations/importer.py +++ b/configurations/importer.py @@ -78,7 +78,7 @@ def install(): 'DJANGO_CONFIGURATION environment variable will ' 'be used.'),) - sys.meta_path.append(SettingsImporter()) + sys.meta_path.insert(0, SettingsImporter()) installed = True # now patch the active runserver command to show a nicer output @@ -145,7 +145,7 @@ class SettingsLoader(object): (self.name, mod.__package__)) try: obj = cls() - except Exception, err: + except Exception as err: raise ImproperlyConfigured("Couldn't load settings '%s.%s': %s" % (mod.__name__, self.name, err)) for name, value in uppercase_attributes(obj).items(): diff --git a/setup.py b/setup.py index 577b686..d41a1cb 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup def read(*parts): file_path = path.join(path.dirname(__file__), *parts) - return codecs.open(file_path).read() + return codecs.open(file_path, encoding='utf-8').read() def find_version(*parts): From d654e560403f9bb6025826e995dba256ed279f7c Mon Sep 17 00:00:00 2001 From: Michael van Tellingen Date: Wed, 30 Jan 2013 21:48:15 +0100 Subject: [PATCH 2/2] Set SECRET_KEY in settings.main --- configurations/tests/settings/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configurations/tests/settings/main.py b/configurations/tests/settings/main.py index ff0259f..4f85f16 100644 --- a/configurations/tests/settings/main.py +++ b/configurations/tests/settings/main.py @@ -1,10 +1,13 @@ import os +import uuid from configurations import Settings class Test(Settings): SITE_ID = 1 + SECRET_KEY = str(uuid.uuid4()) + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3',