diff mbox series

[bitbake-devel] lib/bb/data_smart: add removeFromVar method

Message ID 20251009175300.7480-1-bhstalel@gmail.com
State New
Headers show
Series [bitbake-devel] lib/bb/data_smart: add removeFromVar method | expand

Commit Message

Talel BELHADJ SALEM Oct. 9, 2025, 5:53 p.m. UTC
Tested with:

MY_VARIABLE = "foo hello foo world"
python () {
    d.removeFromVar('MY_VARIABLE', 'foo')
}

$ bitbake-getvar -r example --value MY_VARIABLE
 hello  world

Signed-off-by: Talel BELHAJ SALEM <bhstalel@gmail.com>
---
 lib/bb/data_smart.py | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Yoann Congal Oct. 9, 2025, 5:57 p.m. UTC | #1
Le jeu. 9 oct. 2025 à 19:53, BELHADJ SALEM Talel via lists.openembedded.org
<bhstalel=gmail.com@lists.openembedded.org> a écrit :

> Tested with:
>
> MY_VARIABLE = "foo hello foo world"
> python () {
>     d.removeFromVar('MY_VARIABLE', 'foo')
> }
>
> $ bitbake-getvar -r example --value MY_VARIABLE
>  hello  world
>

Out of curiosity, what does the variable history look like? (same command
without the --value)


> Signed-off-by: Talel BELHAJ SALEM <bhstalel@gmail.com>
> ---
>  lib/bb/data_smart.py | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
> index 2e0d30858..554255f3d 100644
> --- a/lib/bb/data_smart.py
> +++ b/lib/bb/data_smart.py
> @@ -714,6 +714,11 @@ class DataSmart(MutableMapping):
>          self.varhistory.record(**loginfo)
>          self.setVar(var + ":prepend", value, ignore=True, parsing=True)
>
> +    def removeFromVar(self, var, value, **loginfo):
> +        loginfo['op'] = 'remove'
> +        self.varhistory.record(**loginfo)
> +        self.setVar(var + ":remove", value, ignore=True, parsing=True)
> +
>      def delVar(self, var, **loginfo):
>          self.expand_cache = {}
>
> --
> 2.51.0
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#18156):
> https://lists.openembedded.org/g/bitbake-devel/message/18156
> Mute This Topic: https://lists.openembedded.org/mt/115676008/4316185
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [
> yoann.congal@smile.fr]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
Talel BELHADJ SALEM Oct. 9, 2025, 6:02 p.m. UTC | #2
It has two actions on it : set and remove:

$ bitbake-getvar -r example MY_VARIABLE
> #
> # $MY_VARIABLE [2 operations]
> #   set /work/meta-test/recipes-example/example/example_0.1.bb:5
> #     "foo hello foo world"
> #   remove example_0.1.bb:8
> [__anon_9__work_meta_test_recipes_example_example_example_0_1_bb]
> #     "foo"
> # pre-expansion value:
> #   "foo hello foo world"
> MY_VARIABLE=" hello  world"


On Thu, Oct 9, 2025 at 6:57 PM Yoann Congal <yoann.congal@smile.fr> wrote:

>
>
> Le jeu. 9 oct. 2025 à 19:53, BELHADJ SALEM Talel via
> lists.openembedded.org <bhstalel=gmail.com@lists.openembedded.org> a
> écrit :
>
>> Tested with:
>>
>> MY_VARIABLE = "foo hello foo world"
>> python () {
>>     d.removeFromVar('MY_VARIABLE', 'foo')
>> }
>>
>> $ bitbake-getvar -r example --value MY_VARIABLE
>>  hello  world
>>
>
> Out of curiosity, what does the variable history look like? (same command
> without the --value)
>
>
>> Signed-off-by: Talel BELHAJ SALEM <bhstalel@gmail.com>
>> ---
>>  lib/bb/data_smart.py | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
>> index 2e0d30858..554255f3d 100644
>> --- a/lib/bb/data_smart.py
>> +++ b/lib/bb/data_smart.py
>> @@ -714,6 +714,11 @@ class DataSmart(MutableMapping):
>>          self.varhistory.record(**loginfo)
>>          self.setVar(var + ":prepend", value, ignore=True, parsing=True)
>>
>> +    def removeFromVar(self, var, value, **loginfo):
>> +        loginfo['op'] = 'remove'
>> +        self.varhistory.record(**loginfo)
>> +        self.setVar(var + ":remove", value, ignore=True, parsing=True)
>> +
>>      def delVar(self, var, **loginfo):
>>          self.expand_cache = {}
>>
>> --
>> 2.51.0
>>
>>
>> -=-=-=-=-=-=-=-=-=-=-=-
>> Links: You receive all messages sent to this group.
>> View/Reply Online (#18156):
>> https://lists.openembedded.org/g/bitbake-devel/message/18156
>> Mute This Topic: https://lists.openembedded.org/mt/115676008/4316185
>> Group Owner: bitbake-devel+owner@lists.openembedded.org
>> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [
>> yoann.congal@smile.fr]
>> -=-=-=-=-=-=-=-=-=-=-=-
>>
>>
>
> --
> Yoann Congal
> Smile ECS
>
Yoann Congal Oct. 9, 2025, 6:32 p.m. UTC | #3
Le jeu. 9 oct. 2025 à 20:03, Talel BELHADJ SALEM <bhstalel@gmail.com> a
écrit :

> It has two actions on it : set and remove:
>
> $ bitbake-getvar -r example MY_VARIABLE
>> #
>> # $MY_VARIABLE [2 operations]
>> #   set /work/meta-test/recipes-example/example/example_0.1.bb:5
>> #     "foo hello foo world"
>> #   remove example_0.1.bb:8
>> [__anon_9__work_meta_test_recipes_example_example_example_0_1_bb]
>> #     "foo"
>> # pre-expansion value:
>> #   "foo hello foo world"
>> MY_VARIABLE=" hello  world"
>
>
Thank you. It does look good!


> On Thu, Oct 9, 2025 at 6:57 PM Yoann Congal <yoann.congal@smile.fr> wrote:
>
>>
>>
>> Le jeu. 9 oct. 2025 à 19:53, BELHADJ SALEM Talel via
>> lists.openembedded.org <bhstalel=gmail.com@lists.openembedded.org> a
>> écrit :
>>
>>> Tested with:
>>>
>>> MY_VARIABLE = "foo hello foo world"
>>> python () {
>>>     d.removeFromVar('MY_VARIABLE', 'foo')
>>> }
>>>
>>> $ bitbake-getvar -r example --value MY_VARIABLE
>>>  hello  world
>>>
>>
>> Out of curiosity, what does the variable history look like? (same command
>> without the --value)
>>
>>
>>> Signed-off-by: Talel BELHAJ SALEM <bhstalel@gmail.com>
>>> ---
>>>  lib/bb/data_smart.py | 5 +++++
>>>  1 file changed, 5 insertions(+)
>>>
>>> diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
>>> index 2e0d30858..554255f3d 100644
>>> --- a/lib/bb/data_smart.py
>>> +++ b/lib/bb/data_smart.py
>>> @@ -714,6 +714,11 @@ class DataSmart(MutableMapping):
>>>          self.varhistory.record(**loginfo)
>>>          self.setVar(var + ":prepend", value, ignore=True, parsing=True)
>>>
>>> +    def removeFromVar(self, var, value, **loginfo):
>>> +        loginfo['op'] = 'remove'
>>> +        self.varhistory.record(**loginfo)
>>> +        self.setVar(var + ":remove", value, ignore=True, parsing=True)
>>> +
>>>      def delVar(self, var, **loginfo):
>>>          self.expand_cache = {}
>>>
>>> --
>>> 2.51.0
>>>
>>>
>>> -=-=-=-=-=-=-=-=-=-=-=-
>>> Links: You receive all messages sent to this group.
>>> View/Reply Online (#18156):
>>> https://lists.openembedded.org/g/bitbake-devel/message/18156
>>> Mute This Topic: https://lists.openembedded.org/mt/115676008/4316185
>>> Group Owner: bitbake-devel+owner@lists.openembedded.org
>>> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [
>>> yoann.congal@smile.fr]
>>> -=-=-=-=-=-=-=-=-=-=-=-
>>>
>>>
>>
>> --
>> Yoann Congal
>> Smile ECS
>>
>
Ross Burton Nov. 6, 2025, 1:18 p.m. UTC | #4
On 9 Oct 2025, at 18:53, BELHADJ SALEM Talel via lists.openembedded.org <bhstalel=gmail.com@lists.openembedded.org> wrote:
> 
> Tested with:
> 
> MY_VARIABLE = "foo hello foo world"
> python () {
>    d.removeFromVar('MY_VARIABLE', 'foo')
> }
> 
> $ bitbake-getvar -r example --value MY_VARIABLE
> hello  world

I’m curious what the use case for this: if you’re programmatically manipulating the data store can you not just make the desired changes directly, instead of adding another operator which has to be evaluated and has a performance hit?

Ross
Richard Purdie Nov. 7, 2025, 1:42 p.m. UTC | #5
On Thu, 2025-11-06 at 13:18 +0000, Ross Burton via
lists.openembedded.org wrote:
> On 9 Oct 2025, at 18:53, BELHADJ SALEM Talel via
> lists.openembedded.org <bhstalel=gmail.com@lists.openembedded.org>
> wrote:
> > 
> > Tested with:
> > 
> > MY_VARIABLE = "foo hello foo world"
> > python () {
> >    d.removeFromVar('MY_VARIABLE', 'foo')
> > }
> > 
> > $ bitbake-getvar -r example --value MY_VARIABLE
> > hello  world
> 
> I’m curious what the use case for this: if you’re programmatically
> manipulating the data store can you not just make the desired changes
> directly, instead of adding another operator which has to be
> evaluated and has a performance hit?

I haven't taken this as I have the same feelings as Ross. Whilst we can
add API, the real question is whether it does something which is useful
and can't easily be done another way.

In this case, whilst it might have some minor use cases, it can be done
other ways. It also doesn't allow for optimisation, which was the
reason for adding some other APIs.

As such I'm not sure this patch meets the high bar requirements for new
API...

Cheers,

Richard
diff mbox series

Patch

diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
index 2e0d30858..554255f3d 100644
--- a/lib/bb/data_smart.py
+++ b/lib/bb/data_smart.py
@@ -714,6 +714,11 @@  class DataSmart(MutableMapping):
         self.varhistory.record(**loginfo)
         self.setVar(var + ":prepend", value, ignore=True, parsing=True)
 
+    def removeFromVar(self, var, value, **loginfo):
+        loginfo['op'] = 'remove'
+        self.varhistory.record(**loginfo)
+        self.setVar(var + ":remove", value, ignore=True, parsing=True)
+
     def delVar(self, var, **loginfo):
         self.expand_cache = {}