default variables in a python task/function


josh@hipro.co.in
 

Hello,

Considering the following code snippet variants of a recipe which does
the same job, I would like to clarify certain doubts regarding this.

python __anonymous () {
pn_split = d.getVar('PN', True).split('-')
...
}

python __anonymous () {
import bb
pn_split = bb.data.getVar('PN', d, True).split('-')
...
}

In some .bbclass, 'bb' library is used without importing it. I find that
the 'd' variable is an instance of DataSmart class in the bitbake
library. Will this 'bb' and 'd' variables be available to all python
tasks and functions?

I also find that in global python functions such as 'get_imagecmds'
defined in image_types.bbclass 'd' is got as a parameter. Can someone
explain when the 'd' will be initialized? Will the instance of DataSmart
(i.e the variable 'd') in bbclass differ from that of the recipe which
inherited that class? In bitbake manual, example of global python
functions are shown as accepting 'bb' and 'd' variables as its
parameters. Can someone explain the right way of doing this.

Thank you

--
Joshua Immanuel
HiPro IT Solutions Private Limited
http://hipro.co.in


Chris Larson <clarson@...>
 

On Wed, Jun 20, 2012 at 8:46 AM, Joshua Immanuel <josh@...> wrote:
Hello,

Considering the following code snippet variants of a recipe which does
the same job, I would like to clarify certain doubts regarding this.

python __anonymous () {
       pn_split = d.getVar('PN', True).split('-')
       ...
}

python __anonymous () {
       import bb
       pn_split = bb.data.getVar('PN', d, True).split('-')
       ...
}

In some .bbclass, 'bb' library is used without importing it. I find that
the 'd' variable is an instance of DataSmart class in the bitbake
library. Will this 'bb' and 'd' variables be available to all python
tasks and functions?
'bb' and 'os' are always imported, automatically, by bitbake itself,
and as such are available in all python contexts. 'd' is available in
python tasks and anonymous python functions and in inline python
snippets, but *not* in event handlers. event handlers get their event
passed as 'e'.

I also find that in global python functions such as 'get_imagecmds'
defined in image_types.bbclass 'd' is got as a parameter. Can someone
explain when the 'd' will be initialized? Will the instance of DataSmart
(i.e the variable 'd') in bbclass differ from that of the recipe which
inherited that class? In bitbake manual, example of global python
functions are shown as accepting 'bb' and 'd' variables as its
parameters. Can someone explain the right way of doing this.
Unlike 'bb' and 'os', 'd' is not available in def'd python functions,
only in tasks and anonymous functions and in inline python snippets.
As such, it needs to be passed in by the caller.

E.g.

def foo(d):
# do something with d

FOO = "${@foo(d)}"
--
Christopher Larson


josh@hipro.co.in
 

Hello Chris,

On Fri, 2012-06-22 at 18:28 -0700, Chris Larson wrote:
'bb' and 'os' are always imported, automatically, by bitbake itself,
and as such are available in all python contexts. 'd' is available in
python tasks and anonymous python functions and in inline python
snippets, but *not* in event handlers. event handlers get their event
passed as 'e'.
...
Unlike 'bb' and 'os', 'd' is not available in def'd python functions,
only in tasks and anonymous functions and in inline python snippets.
As such, it needs to be passed in by the caller.

E.g.

def foo(d):
# do something with d

FOO = "${@foo(d)}"
Thanks for your detailed explanation.

IMHO, this information should be added in the main documentation. It
would be definitely helpful for others too.

Regards
--
Joshua Immanuel
HiPro IT Solutions Private Limited
http://hipro.co.in