Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] _LazyImportFrom._get_target: handle submodule import (bug 550906)
Date: Thu, 11 Jun 2015 07:17:19
Message-Id: 20150611001713.27d84ad5.dolsen@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] _LazyImportFrom._get_target: handle submodule import (bug 550906) by Zac Medico
1 On Sun, 31 May 2015 13:32:58 -0700
2 Zac Medico <zmedico@g.o> wrote:
3
4 > Since commit 1032cbf4c218741df1c57767fead2d00cc6321d9,
5 > PreloadPortageSubmodulesTestCase fails because
6 > _LazyImportFrom._get_target does not try to import submodules.
7 > Fix it to do so.
8 >
9 > Fixes: 1032cbf4c218 ("quickpkg: support FEATURES=xattr (bug 550006)")
10 > X-Gentoo-Bug: 550906
11 > X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=550906
12 > ---
13 > pym/portage/proxy/lazyimport.py | 17 +++++++++++++----
14 > 1 file changed, 13 insertions(+), 4 deletions(-)
15 >
16 > diff --git a/pym/portage/proxy/lazyimport.py
17 > b/pym/portage/proxy/lazyimport.py index 5aa7e50..d425870 100644
18 > --- a/pym/portage/proxy/lazyimport.py
19 > +++ b/pym/portage/proxy/lazyimport.py
20 > @@ -128,10 +128,19 @@ class _LazyImportFrom(_LazyImport):
21 > name = object.__getattribute__(self, '_name')
22 > attr_name = object.__getattribute__(self,
23 > '_attr_name') __import__(name)
24 > - # If called by _unregister_module_proxy() and the
25 > target module is
26 > - # partially imported, then the following getattr
27 > call may raise an
28 > - # AttributeError for _unregister_module_proxy() to
29 > handle.
30 > - target = getattr(sys.modules[name], attr_name)
31 > + try:
32 > + target = getattr(sys.modules[name],
33 > attr_name)
34 > + except AttributeError:
35 > + # Try to import it as a submodule
36 > + try:
37 > + __import__("%s.%s" % (name,
38 > attr_name))
39 > + except ImportError:
40 > + pass
41 > + # If it's a submodule, this will succeed.
42 > Otherwise, it may
43 > + # be that the module is only partially
44 > imported, so raise
45 > + # AttributeError for
46 > _unregister_module_proxy() to handle.
47 > + target = getattr(sys.modules[name],
48 > attr_name) +
49 > object.__setattr__(self, '_target', target)
50 > object.__getattribute__(self, '_scope')[
51 > object.__getattribute__(self, '_alias')] =
52 > target
53
54 confirmation of approval... already pushed.
55
56 --
57 Brian Dolbec <dolsen>