11606cabab0d — Peter Sanchez 13 years ago
Now using version string in setup.py for pypi interaction. Avoid import errors with install
3 files changed, 50 insertions(+), 55 deletions(-)

M easyconfig/__init__.py
R easyconfig/config.py => 
M setup.py
M easyconfig/__init__.py +48 -2
@@ 1,5 1,51 @@ 
-from config import EasyConfig
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+from django.utils.importlib import import_module
 
 
 __version__ = '0.1'
-__all__ = ['EasyConfig',]
+
+class EasyConfig(object):
+    def __init__(self, default_module, setting_name):
+        self.default_module = default_module
+        self.setting_name = setting_name
+
+    def _get_config(self):
+        ''' Get the config as defined in the settings
+        '''
+        config = self._get_config_name()
+        try:
+            package = import_module(config)
+        except ImportError:
+            path = '.'.join(config.split('.')[:-1])
+            pkg = config.split('.')[-1]
+            try:
+                tmp_package = import_module(path, package=pkg)
+                package = getattr(tmp_package, pkg)
+            except (ImportError, AttributeError):
+                raise ImproperlyConfigured(
+                    'The %s setting refers to a non-existing package.' % \
+                                                            self.setting_name
+                )
+        
+        if callable(package):
+            package = package()
+        return package
+
+    def _get_config_name(self):
+        ''' Returns the name of the support config (either the setting value, 
+            if it exists, or the default).
+        '''
+        return getattr(settings, self.setting_name, self.default_module)
+
+
+    def get_object(self, method, default_obj, *args, **kwargs):
+        ''' Check that the support config is custom, and if so, that the 
+            right methods exist. If not, return the default_obj
+        '''
+        if self._get_config_name() != self.default_module:
+            config = self._get_config()
+            if hasattr(config, method):
+                return getattr(config, method)(*args, **kwargs)
+
+        return default_obj

          
R easyconfig/config.py =>  +0 -52
@@ 1,52 0,0 @@ 
-from django.conf import settings
-from django.core.exceptions import ImproperlyConfigured
-from django.utils.importlib import import_module
-
-
-__version__ = '0.1'
-
-
-class EasyConfig(object):
-    def __init__(self, default_module, setting_name):
-        self.default_module = default_module
-        self.setting_name = setting_name
-
-    def _get_config(self):
-        ''' Get the config as defined in the settings
-        '''
-        config = self._get_config_name()
-        try:
-            package = import_module(config)
-        except ImportError:
-            path = '.'.join(config.split('.')[:-1])
-            pkg = config.split('.')[-1]
-            try:
-                tmp_package = import_module(path, package=pkg)
-                package = getattr(tmp_package, pkg)
-            except (ImportError, AttributeError):
-                raise ImproperlyConfigured(
-                    'The %s setting refers to a non-existing package.' % \
-                                                            self.setting_name
-                )
-        
-        if callable(package):
-            package = package()
-        return package
-
-    def _get_config_name(self):
-        ''' Returns the name of the support config (either the setting value, 
-            if it exists, or the default).
-        '''
-        return getattr(settings, self.setting_name, self.default_module)
-
-
-    def get_object(self, method, default_obj, *args, **kwargs):
-        ''' Check that the support config is custom, and if so, that the 
-            right methods exist. If not, return the default_obj
-        '''
-        if self._get_config_name() != self.default_module:
-            config = self._get_config()
-            if hasattr(config, method):
-                return getattr(config, method)(*args, **kwargs)
-
-        return default_obj

          
M setup.py +2 -1
@@ 2,6 2,7 @@ import os
 from distutils.core import setup
 
 
+version = '0.1'
 project_name = 'easyconfig'
 long_description = open('README.txt').read()
 

          
@@ 28,7 29,7 @@ for dirpath, dirnames, filenames in os.w
 
 setup(
     name='django-easyconfig',
-    version=__import__(project_name).__version__,
+    version=version,
     package_dir={project_name: project_name},
     packages=packages,
     package_data={project_name: data_files},