1 |
Since commit 1032cbf4c218741df1c57767fead2d00cc6321d9, |
2 |
PreloadPortageSubmodulesTestCase fails because |
3 |
_LazyImportFrom._get_target does not try to import submodules. |
4 |
Fix it to do so. |
5 |
|
6 |
Fixes: 1032cbf4c218 ("quickpkg: support FEATURES=xattr (bug 550006)") |
7 |
X-Gentoo-Bug: 550906 |
8 |
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=550906 |
9 |
--- |
10 |
pym/portage/proxy/lazyimport.py | 17 +++++++++++++---- |
11 |
1 file changed, 13 insertions(+), 4 deletions(-) |
12 |
|
13 |
diff --git a/pym/portage/proxy/lazyimport.py b/pym/portage/proxy/lazyimport.py |
14 |
index 5aa7e50..d425870 100644 |
15 |
--- a/pym/portage/proxy/lazyimport.py |
16 |
+++ b/pym/portage/proxy/lazyimport.py |
17 |
@@ -128,10 +128,19 @@ class _LazyImportFrom(_LazyImport): |
18 |
name = object.__getattribute__(self, '_name') |
19 |
attr_name = object.__getattribute__(self, '_attr_name') |
20 |
__import__(name) |
21 |
- # If called by _unregister_module_proxy() and the target module is |
22 |
- # partially imported, then the following getattr call may raise an |
23 |
- # AttributeError for _unregister_module_proxy() to handle. |
24 |
- target = getattr(sys.modules[name], attr_name) |
25 |
+ try: |
26 |
+ target = getattr(sys.modules[name], attr_name) |
27 |
+ except AttributeError: |
28 |
+ # Try to import it as a submodule |
29 |
+ try: |
30 |
+ __import__("%s.%s" % (name, attr_name)) |
31 |
+ except ImportError: |
32 |
+ pass |
33 |
+ # If it's a submodule, this will succeed. Otherwise, it may |
34 |
+ # be that the module is only partially imported, so raise |
35 |
+ # AttributeError for _unregister_module_proxy() to handle. |
36 |
+ target = getattr(sys.modules[name], attr_name) |
37 |
+ |
38 |
object.__setattr__(self, '_target', target) |
39 |
object.__getattribute__(self, '_scope')[ |
40 |
object.__getattribute__(self, '_alias')] = target |
41 |
-- |
42 |
2.3.5 |