]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- don't need resolve, don't need import for this. just look in sys.modules,
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Aug 2013 19:03:50 +0000 (15:03 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Aug 2013 19:03:50 +0000 (15:03 -0400)
since we are dealing with cycles in any case.

lib/sqlalchemy/__init__.py
lib/sqlalchemy/engine/__init__.py
lib/sqlalchemy/orm/__init__.py
lib/sqlalchemy/util/langhelpers.py

index 2c805e607e96f69a1ee4f4fca556d76c65d70ff0..61892e02ed2403562bb40a6e46ccadaf37ee4408 100644 (file)
@@ -124,5 +124,3 @@ __version__ = '0.9.0'
 
 del _inspect, sys
 
-from . import util as _sa_util
-_sa_util.importlater.resolve_all()
index 0a5a96784a2a565e4155f8717bb42232b32ec470..a00976d4c3f345e79ece673a15ffc52baf2f6d4d 100644 (file)
@@ -83,7 +83,7 @@ from .util import (
     connection_memoize
     )
 
-from . import util, strategies
+from . import util, strategies, ddl
 
 default_strategy = 'plain'
 
index 1173d5d0961fa88e79cb4089c33b95ede97039d1..797569ce8e25015b89863a3b0bcffda4edaa0195 100644 (file)
@@ -1782,5 +1782,3 @@ def undefer_group(name):
     """
     return strategies.UndeferGroupOption(name)
 
-from sqlalchemy import util as _sa_util
-_sa_util.importlater.resolve_all()
index ef1ff881dc1ce812ef33be1dfc12d841a195a6ef..430c630a85e91c8c65eb48d41ce159f68a374e07 100644 (file)
@@ -688,62 +688,36 @@ class importlater(object):
 
     except evaluted upon attribute access to "somesubmod".
 
-    importlater() currently requires that resolve_all() be
-    called, typically at the bottom of a package's __init__.py.
-    This is so that __import__ still called only at
-    module import time, and not potentially within
-    a non-main thread later on.
+    importlater() relies on sys.modules being populated with the
+    target package, and the target package containing the target module,
+    by time the attribute is evaulated.
 
     """
 
-    _unresolved = set()
-
-    def __init__(self, path, addtl=None):
+    def __init__(self, path, addtl):
         self._il_path = path
         self._il_addtl = addtl
-        importlater._unresolved.add(self)
-
-    @classmethod
-    def resolve_all(cls):
-        for m in list(importlater._unresolved):
-            m._resolve()
 
     @property
     def _full_path(self):
-        if self._il_addtl:
-            return self._il_path + "." + self._il_addtl
-        else:
-            return self._il_path
+        return self._il_path + "." + self._il_addtl
 
     @memoized_property
     def module(self):
-        if self in importlater._unresolved:
-            raise ImportError(
-                    "importlater.resolve_all() hasn't "
-                    "been called (this is %s %s)"
-                    % (self._il_path, self._il_addtl))
-
-        m = self._initial_import
-        if self._il_addtl:
-            m = getattr(m, self._il_addtl)
-        else:
-            for token in self._il_path.split(".")[1:]:
-                m = getattr(m, token)
-        return m
-
-    def _resolve(self):
-        importlater._unresolved.discard(self)
-        if self._il_addtl:
-            self._initial_import = compat.import_(
-                                self._il_path, globals(), locals(),
-                                [self._il_addtl])
+        try:
+            m = sys.modules[self._il_path]
+        except KeyError:
+            raise KeyError("Module %s hasn't been installed" % self._il_path)
         else:
-            self._initial_import = compat.import_(self._il_path)
+            try:
+                return getattr(m, self._il_addtl)
+            except AttributeError:
+                raise KeyError(
+                        "Module %s hasn't been installed into %s" %
+                        (self._il_addtl, self._il_path)
+                    )
 
     def __getattr__(self, key):
-        if key == 'module':
-            raise ImportError("Could not resolve module %s"
-                                % self._full_path)
         try:
             attr = getattr(self.module, key)
         except AttributeError: