joerussbowman / gaeutilities

gaeutilities - A collection of utilities to help with application development on Google Appengine
http://gaeutilities.appspot.com
BSD 3-Clause "New" or "Revised" License
78 stars 4 forks source link

Please consider not using relative imports for modules not guaranteed to be there #10

Closed posita closed 14 years ago

posita commented 14 years ago

This is true of your settings import from sessions.py. It may clash when appengine_utilities is used in apps which have top-level 'settings' modules and appengine_utilities/settings.py is not present. Please consider the following patch (or something similar):

diff -Naruw appengine_utilities.orig/sessions.py appengine_utilities/sessions.py
--- appengine_utilities.orig/sessions.py    2009-09-27 20:20:26.000000000 -0700
+++ appengine_utilities/sessions.py 2010-03-14 12:24:19.000000000 -0700
@@ -48,9 +48,13 @@

 # settings
 try:
+    import settings_default
     import settings
+
+    if settings.__name__.rsplit('.', 1)[0] != settings_default.__name__.rsplit('.', 1)[0]:
+        settings = settings_default
 except:
-    import settings_default as settings
+    settings = settings_default

 class _AppEngineUtilities_Session(ROTModel):
posita commented 14 years ago

Alternatively, consider creating a settings.py file that contains:

from settings_default import *
joerussbowman commented 14 years ago

Ok, your first patch has been added to the master branch. Thanks!

posita commented 14 years ago

After some thought a minimal settings.py file seems less hack-like than the above patch, but (of course) it's up to you. :o)

joerussbowman commented 14 years ago

I'm more worried that having the file with that in place would just confuse the purpose, which is to get people to create the settings.py file if they need it. So while a bit hacking, I believe it's more helpful for the developer new to the environment to figure out what to do.