Skip to contentSkip to conversation

default variables in a python task/function

DISCUSSION Joshua Immanuel 2 participants 3 messages Jun 20, 2012 – Jun 25, 2012

lore
Share & tools
lore
#0 lore raw

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

Signature · 3 lines
Joshua Immanuel
HiPro IT Solutions Private Limited
http://hipro.co.in
#1 lore raw
Quoted 16 lines · Joshua Immanuel

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('-')
       ...
}

Quoted 4 lines

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'.

Quoted 7 lines

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)}"

Signature · 1 line
Christopher Larson
#2 lore raw

Hello Chris,

Quoted 10 lines · Chris Larson

'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.

Quoted 6 lines

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

Signature · 3 lines
Joshua Immanuel
HiPro IT Solutions Private Limited
http://hipro.co.in