[poky] [PATCH 3/7] bb: add bb.fetcher as dynamic fetch module instance for fetch/fetch2

Richard Purdie richard.purdie at linuxfoundation.org
Mon Jan 10 16:50:50 PST 2011


On Tue, 2011-01-11 at 08:13 +0800, Yu Ke wrote:
> > If we assume bb.fetch2 will not make calls to bb.fetch we can simplify
> > this to:
> > 
> > if os.environ.get("BBFETCH2"):
> >     from bb import fetch2 as fetch
> >     sys.modules['bb.fetch'] = sys.modules['bb.fetch2']
> 
> BTW, a quick question. with sys.modules['bb.fetch'] =
> sys.modules['bb.fetch2'], will the future "import bb.fetch" override
> the bb.fetch in namespeace ? I assume not, but just want to double
> confirm. I know that "import <module>" will not be executed if the
> <module> is already imported. So does python use sys.modules[<module>]
> to decide if it is already imported?

This is correct, yes. Python uses sys.modules behind the scenes when it
sees "import X". You can prove this by placing a sys.exit(1) in the
bb.fetch code :)

Cheers,

Richard






More information about the poky mailing list