All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Joshua Lock <josh@openedhand.com>
Cc: poky@yoctoproject.org
Subject: Re: [PATCH 3/7] bb: add bb.fetcher as dynamic fetch module instance for fetch/fetch2
Date: Mon, 10 Jan 2011 11:42:54 +0000	[thread overview]
Message-ID: <1294659774.1492.186.camel@rex> (raw)
In-Reply-To: <1294654419.2451.3.camel@scimitar>

On Mon, 2011-01-10 at 10:13 +0000, Joshua Lock wrote:
> On Sat, 2011-01-08 at 15:15 +0800, Yu Ke wrote:
> > bb.fetcher is introduced to swtich between bb.fetch and bb.fetch2.
> > all bb.fetch/bb.fetch2 referrence can be replaced with bb.fetcher.instance,
> > so that we can cleanly switch between bb.fetch and bb.fetch2
> > 
> > Signed-off-by: Yu Ke <ke.yu@intel.com>
> > ---
> >  bitbake/lib/bb/fetcher.py |   26 ++++++++++++++++++++++++++
> >  1 files changed, 26 insertions(+), 0 deletions(-)
> >  create mode 100644 bitbake/lib/bb/fetcher.py
> > 
> > diff --git a/bitbake/lib/bb/fetcher.py b/bitbake/lib/bb/fetcher.py
> > new file mode 100644
> > index 0000000..3818d78
> > --- /dev/null
> > +++ b/bitbake/lib/bb/fetcher.py
> > @@ -0,0 +1,26 @@
> > +#!/usr/bin/env python
> > +# ex:ts=4:sw=4:sts=4:et
> > +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License version 2 as
> > +# published by the Free Software Foundation.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License along
> > +# with this program; if not, write to the Free Software Foundation, Inc.,
> > +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> > +
> > +import bb
> > +from bb import fetch, fetch2
> > +
> > +# switch between fetch and fetch2
> > +instance = bb.fetch
> > +__version__ = "1"
> > +
> > +#instance = bb.fetch2
> > +#__version__ = "2"
> 
> I'm not very happy with this, it doesn't feel right. Can we not add some
> runtime determination of which module to use (a variable in
> bitbake.conf?) and then use some dynamic Python magic to add it to the
> imported modules list?
> 
> A quick Google makes me thing we could do something more dynamic with
> the __import__() function.

Agreed, I was also thinking about this but wanted to come up with a
suggestion about how to better handle it. There is some interesting info
in this webpage:

http://stackoverflow.com/questions/1096216/override-namespace-in-python

This example in particular looks useful:

def weirdimport(fullpath):
  global project

  import os
  import sys
  sys.path.append(os.path.dirname(fullpath))
  try:
      project = __import__(os.path.basename(fullpath))
      sys.modules['project'] = project
  finally:
      del sys.path[-1]

Although we shouldn't need to manipulate sys.path in our case.

As Joshua mentions, overriding the __import__ builtin should also work
and might avoid some ordering issues we'd have with the above.

Cheers,

Richard




  reply	other threads:[~2011-01-10 11:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-08  7:14 [PATCH 0/7] add initial bb.fetch2 code Yu Ke
2011-01-08  7:14 ` [PATCH 1/7] fetch2: copy bb.fetch to bb.fetch2 as initial code base Yu Ke
2011-01-08  7:15 ` [PATCH 2/7] bb.fetch2: replace bb.fetch with bb.fetch2 in the bb.fetch2 Yu Ke
2011-01-08  7:15 ` [PATCH 3/7] bb: add bb.fetcher as dynamic fetch module instance for fetch/fetch2 Yu Ke
2011-01-10 10:13   ` Joshua Lock
2011-01-10 11:42     ` Richard Purdie [this message]
2011-01-10 16:43       ` Richard Purdie
2011-01-10 20:19         ` Richard Purdie
2011-01-11  0:06           ` Yu Ke
2011-01-11  0:13           ` Yu Ke
2011-01-11  0:50             ` Richard Purdie
2011-01-11  1:16               ` Yu Ke
2011-01-11 11:54           ` Joshua Lock
2011-01-08  7:15 ` [PATCH 4/7] BBHandler: remove bb.fetch referrence Yu Ke
2011-01-08  7:15 ` [PATCH 5/7] bb.cooker: remove bb.fetch.persistent_database_connection referrence Yu Ke
2011-01-08  7:15 ` [PATCH 6/7] bb: replace bb.fetch referrence with bb.fetcher instance Yu Ke
2011-01-08  7:15 ` [PATCH 7/7] bbclass: replace the " Yu Ke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1294659774.1492.186.camel@rex \
    --to=richard.purdie@linuxfoundation.org \
    --cc=josh@openedhand.com \
    --cc=poky@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.