commit: 7a63f955b8da06c565ea342975014511b1cc2bd3
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May 31 20:32:13 2015 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Jun 5 01:31:26 2015 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7a63f955
_LazyImportFrom._get_target: handle submodule import (bug 550906)
Since commit 1032cbf4c218741df1c57767fead2d00cc6321d9,
PreloadPortageSubmodulesTestCase fails because
_LazyImportFrom._get_target does not try to import submodules.
Fix it to do so.
Fixes: 1032cbf4c218 ("quickpkg: support FEATURES=xattr (bug 550006)")
X-Gentoo-Bug: 550906
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=550906
pym/portage/proxy/lazyimport.py | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/pym/portage/proxy/lazyimport.py b/pym/portage/proxy/lazyimport.py
index 5aa7e50..d425870 100644
--- a/pym/portage/proxy/lazyimport.py
+++ b/pym/portage/proxy/lazyimport.py
@@ -128,10 +128,19 @@ class _LazyImportFrom(_LazyImport):
name = object.__getattribute__(self, '_name')
attr_name = object.__getattribute__(self, '_attr_name')
__import__(name)
- # If called by _unregister_module_proxy() and the target module
is
- # partially imported, then the following getattr call may raise
an
- # AttributeError for _unregister_module_proxy() to handle.
- target = getattr(sys.modules[name], attr_name)
+ try:
+ target = getattr(sys.modules[name], attr_name)
+ except AttributeError:
+ # Try to import it as a submodule
+ try:
+ __import__("%s.%s" % (name, attr_name))
+ except ImportError:
+ pass
+ # If it's a submodule, this will succeed. Otherwise, it
may
+ # be that the module is only partially imported, so
raise
+ # AttributeError for _unregister_module_proxy() to
handle.
+ target = getattr(sys.modules[name], attr_name)
+
object.__setattr__(self, '_target', target)
object.__getattribute__(self, '_scope')[
object.__getattribute__(self, '_alias')] = target