From e0237aac2ba992a5c31206fea52f55969db65ba0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 4 Aug 2013 15:03:50 -0400 Subject: [PATCH] - don't need resolve, don't need import for this. just look in sys.modules, since we are dealing with cycles in any case. --- lib/sqlalchemy/__init__.py | 2 -- lib/sqlalchemy/engine/__init__.py | 2 +- lib/sqlalchemy/orm/__init__.py | 2 -- lib/sqlalchemy/util/langhelpers.py | 58 +++++++++--------------------- 4 files changed, 17 insertions(+), 47 deletions(-) diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 2c805e607e..61892e02ed 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -124,5 +124,3 @@ __version__ = '0.9.0' del _inspect, sys -from . import util as _sa_util -_sa_util.importlater.resolve_all() diff --git a/lib/sqlalchemy/engine/__init__.py b/lib/sqlalchemy/engine/__init__.py index 0a5a96784a..a00976d4c3 100644 --- a/lib/sqlalchemy/engine/__init__.py +++ b/lib/sqlalchemy/engine/__init__.py @@ -83,7 +83,7 @@ from .util import ( connection_memoize ) -from . import util, strategies +from . import util, strategies, ddl default_strategy = 'plain' diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index 1173d5d096..797569ce8e 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -1782,5 +1782,3 @@ def undefer_group(name): """ return strategies.UndeferGroupOption(name) -from sqlalchemy import util as _sa_util -_sa_util.importlater.resolve_all() diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index ef1ff881dc..430c630a85 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -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: -- 2.47.3