public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] _LazyImportFrom._get_target: handle submodule import (bug 550906)
@ 2015-05-31 20:32 Zac Medico
  2015-06-11  7:17 ` Brian Dolbec
  0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2015-05-31 20:32 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

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
-- 
2.3.5



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-11  7:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-31 20:32 [gentoo-portage-dev] [PATCH] _LazyImportFrom._get_target: handle submodule import (bug 550906) Zac Medico
2015-06-11  7:17 ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox