← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/death-import-star into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/death-import-star into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/death-import-star/+merge/97659
-- 
https://code.launchpad.net/~allenap/maas/death-import-star/+merge/97659
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/death-import-star into lp:maas.
=== modified file 'Makefile'
--- Makefile	2012-03-14 16:01:19 +0000
+++ Makefile	2012-03-15 13:59:18 +0000
@@ -54,8 +54,7 @@
 
 lint: sources = setup.py src templates utilities
 lint: bin/flake8
-	@bin/flake8 $(sources) | \
-	    (! egrep -v "from maas[.](settings|development) import [*]")
+	@bin/flake8 $(sources)
 
 check: clean test
 

=== modified file 'buildout.cfg'
--- buildout.cfg	2012-03-14 16:01:19 +0000
+++ buildout.cfg	2012-03-15 13:59:18 +0000
@@ -42,7 +42,6 @@
   Sphinx
   docutils
   lxml
-  ipython
 
 prefer-final = true
 allow-picked-versions = false

=== modified file 'src/maas/__init__.py'
--- src/maas/__init__.py	2012-01-16 08:33:18 +0000
+++ src/maas/__init__.py	2012-03-15 13:59:18 +0000
@@ -0,0 +1,48 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""MAAS web."""
+
+from __future__ import (
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = [
+    "import_settings",
+    "import_local_settings",
+    ]
+
+import sys
+
+
+def find_settings(whence):
+    """Return settings from `whence`, which is assumed to be a module."""
+    return {
+        name: value
+        for name, value in vars(whence).items()
+        if not name.startswith("_")
+        }
+
+
+def import_settings(whence):
+    """Import settings from `whence` into the caller's global scope."""
+    source = find_settings(whence)
+    target = sys._getframe(1).f_globals
+    target.update(source)
+
+
+def import_local_settings():
+    """Import local settings into the caller's global scope.
+
+    Local settings means settings defined in a `maas_local_settings` module.
+    """
+    try:
+        import maas_local_settings as whence
+    except ImportError:
+        pass
+    else:
+        source = find_settings(whence)
+        target = sys._getframe(1).f_globals
+        target.update(source)

=== modified file 'src/maas/demo.py'
--- src/maas/demo.py	2012-03-15 11:27:27 +0000
+++ src/maas/demo.py	2012-03-15 13:59:18 +0000
@@ -12,11 +12,18 @@
 
 import os
 
-# FIRST: developement settings should override base settings.
-from maas.settings import *
-
-from maas.development import *
-
+from maas import (
+    development,
+    import_settings,
+    settings,
+    )
+
+# We expect the following settings to be overridden.
+MIDDLEWARE_CLASSES = None
+
+# Extend base and development settings.
+import_settings(settings)
+import_settings(development)
 
 MEDIA_ROOT = os.path.join(os.getcwd(), "media/demo")
 

=== modified file 'src/maas/development.py'
--- src/maas/development.py	2012-03-13 11:02:14 +0000
+++ src/maas/development.py	2012-03-15 13:59:18 +0000
@@ -13,7 +13,17 @@
 import os
 from socket import gethostname
 
-from maas.settings import *
+from maas import (
+    import_local_settings,
+    import_settings,
+    settings,
+    )
+
+# We expect the following settings to be overridden.
+INSTALLED_APPS = None
+
+# Extend base settings.
+import_settings(settings)
 
 # In development, django can be accessed directly on port 8000.
 DEFAULT_MAAS_URL = "http://%s:8000/"; % gethostname()
@@ -52,14 +62,11 @@
     'django_nose',
 )
 
-
 INTERNAL_IPS = ('127.0.0.1',)
 
 DEBUG_TOOLBAR_CONFIG = {
     'INTERCEPT_REDIRECTS': False,
     }
 
-try:
-    from maas_local_settings import * # NOQA
-except ImportError:
-    pass
+# Allow the user to override settings in maas_local_settings.
+import_local_settings()

=== modified file 'src/maas/production.py'
--- src/maas/production.py	2012-02-09 16:46:42 +0000
+++ src/maas/production.py	2012-03-15 13:59:18 +0000
@@ -9,9 +9,14 @@
     )
 
 __metaclass__ = type
-__all__ = []
-
-from maas.settings import *
+
+from maas import (
+    import_settings,
+    settings,
+    )
+
+
+import_settings(settings)
 
 # Location where python-oops should store errors.
 OOPS_REPOSITORY = '/var/log/maas'

=== modified file 'src/maas/settings.py'
--- src/maas/settings.py	2012-03-15 11:16:37 +0000
+++ src/maas/settings.py	2012-03-15 13:59:18 +0000
@@ -17,6 +17,7 @@
 # Use new style url tag:
 # https://docs.djangoproject.com/en/dev/releases/1.3/#changes-to-url-and-ssi
 import django.template
+from maas import import_local_settings
 
 
 django.template.add_to_builtins('django.templatetags.future')
@@ -26,11 +27,10 @@
 # Used to set a prefix in front of every URL.
 FORCE_SCRIPT_NAME = None
 
-# Allow the user to override settings in maas_local_settings.
-try:
-    from maas_local_settings import * # NOQA
-except ImportError:
-    pass
+# Allow the user to override settings in maas_local_settings. Later settings
+# depend on the values of DEBUG and FORCE_SCRIPT_NAME, so we must import local
+# settings now in case those settings have been overridden.
+import_local_settings()
 
 ADMINS = (
     # ('Your Name', 'your_email@xxxxxxxxxxx'),
@@ -253,7 +253,5 @@
 # use the fake Provisioning API.
 PSERV_URL = None
 
-try:
-    from maas_local_settings import * # NOQA
-except ImportError:
-    pass
+# Allow the user to override settings in maas_local_settings.
+import_local_settings()