Message ID | 20230523150906.409543-1-andrea.righi@canonical.com |
---|---|
State | New |
Headers | show |
Series | [SRU,M,L,J] UBUNTU: [Packaging] kconfig/annotations.py: support older way of merging dicts | expand |
On 5/23/23 09:09, Andrea Righi wrote: > BugLink: https://bugs.launchpad.net/bugs/2020531 > > The '|=' update operator for merging dicts is available starting in > python 3.9 however in focal we have python 3.8, which causes the > annotation parsing script to crash. > > Support also the old way of merging dicts available since python 3.5 > that uses dict unpacking, e.g. dict1 = {**dict1, **dict2} > > Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> > Signed-off-by: Andrea Righi <andrea.righi@canonical.com> > --- > debian/scripts/misc/kconfig/annotations.py | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py > index dcc133dbbf62..b521bd0c7135 100644 > --- a/debian/scripts/misc/kconfig/annotations.py > +++ b/debian/scripts/misc/kconfig/annotations.py > @@ -105,7 +105,10 @@ class Annotation(Config): > m = re.match(r'.* policy<(.*?)>', line) > if m: > match = True > - entry['policy'] |= literal_eval(m.group(1)) > + try: > + entry['policy'] |= literal_eval(m.group(1)) > + except TypeError: > + entry['policy'] = {**entry['policy'], **literal_eval(m.group(1))} > > m = re.match(r'.* note<(.*?)>', line) > if m: > @@ -204,7 +207,10 @@ class Annotation(Config): > # Determine if we need to import all configs or a single config > if not configs: > configs = c.config.keys() > - configs |= self.search_config(arch=arch, flavour=flavour).keys() > + try: > + configs |= self.search_config(arch=arch, flavour=flavour).keys() > + except TypeError: > + configs = {**configs, **self.search_config(arch=arch, flavour=flavour).keys()} > > # Import configs from the Kconfig object into Annotations > if flavour is not None: > @@ -335,8 +341,12 @@ class Annotation(Config): > # If new_val is a subset of old_val, skip it > old_val = tmp_a.config.get(conf) > if old_val and 'policy' in old_val: > - if old_val['policy'] == old_val['policy'] | new_val['policy']: > - continue > + try: > + if old_val['policy'] == old_val['policy'] | new_val['policy']: > + continue > + except TypeError: > + if old_val['policy'] == {**old_val['policy'], **new_val['policy']}: > + continue > > # Write out the policy (and note) line(s) > val = dict(sorted(new_val['policy'].items())) Acked-by: Tim Gardner <tim.gardner@canonical.com>
Can I ack a patch I co-authored? :) Acked-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> On Tue, May 23, 2023 at 8:09 AM Andrea Righi <andrea.righi@canonical.com> wrote: > BugLink: https://bugs.launchpad.net/bugs/2020531 > > The '|=' update operator for merging dicts is available starting in > python 3.9 however in focal we have python 3.8, which causes the > annotation parsing script to crash. > > Support also the old way of merging dicts available since python 3.5 > that uses dict unpacking, e.g. dict1 = {**dict1, **dict2} > > Signed-off-by: Luke Nowakowski-Krijger < > luke.nowakowskikrijger@canonical.com> > Signed-off-by: Andrea Righi <andrea.righi@canonical.com> > --- > debian/scripts/misc/kconfig/annotations.py | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/debian/scripts/misc/kconfig/annotations.py > b/debian/scripts/misc/kconfig/annotations.py > index dcc133dbbf62..b521bd0c7135 100644 > --- a/debian/scripts/misc/kconfig/annotations.py > +++ b/debian/scripts/misc/kconfig/annotations.py > @@ -105,7 +105,10 @@ class Annotation(Config): > m = re.match(r'.* policy<(.*?)>', line) > if m: > match = True > - entry['policy'] |= literal_eval(m.group(1)) > + try: > + entry['policy'] |= literal_eval(m.group(1)) > + except TypeError: > + entry['policy'] = {**entry['policy'], > **literal_eval(m.group(1))} > > m = re.match(r'.* note<(.*?)>', line) > if m: > @@ -204,7 +207,10 @@ class Annotation(Config): > # Determine if we need to import all configs or a single config > if not configs: > configs = c.config.keys() > - configs |= self.search_config(arch=arch, > flavour=flavour).keys() > + try: > + configs |= self.search_config(arch=arch, > flavour=flavour).keys() > + except TypeError: > + configs = {**configs, **self.search_config(arch=arch, > flavour=flavour).keys()} > > # Import configs from the Kconfig object into Annotations > if flavour is not None: > @@ -335,8 +341,12 @@ class Annotation(Config): > # If new_val is a subset of old_val, skip it > old_val = tmp_a.config.get(conf) > if old_val and 'policy' in old_val: > - if old_val['policy'] == old_val['policy'] | > new_val['policy']: > - continue > + try: > + if old_val['policy'] == old_val['policy'] | > new_val['policy']: > + continue > + except TypeError: > + if old_val['policy'] == {**old_val['policy'], > **new_val['policy']}: > + continue > > # Write out the policy (and note) line(s) > val = dict(sorted(new_val['policy'].items())) > -- > 2.39.2 > > > -- > kernel-team mailing list > kernel-team@lists.ubuntu.com > https://lists.ubuntu.com/mailman/listinfo/kernel-team >
Applied to lunar and jammy linux master-next as well as directly to focal:linux-hwe-5.15 master-next to pick up for this cycle. Thanks, - Luke On Tue, May 23, 2023 at 8:09 AM Andrea Righi <andrea.righi@canonical.com> wrote: > BugLink: https://bugs.launchpad.net/bugs/2020531 > > The '|=' update operator for merging dicts is available starting in > python 3.9 however in focal we have python 3.8, which causes the > annotation parsing script to crash. > > Support also the old way of merging dicts available since python 3.5 > that uses dict unpacking, e.g. dict1 = {**dict1, **dict2} > > Signed-off-by: Luke Nowakowski-Krijger < > luke.nowakowskikrijger@canonical.com> > Signed-off-by: Andrea Righi <andrea.righi@canonical.com> > --- > debian/scripts/misc/kconfig/annotations.py | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/debian/scripts/misc/kconfig/annotations.py > b/debian/scripts/misc/kconfig/annotations.py > index dcc133dbbf62..b521bd0c7135 100644 > --- a/debian/scripts/misc/kconfig/annotations.py > +++ b/debian/scripts/misc/kconfig/annotations.py > @@ -105,7 +105,10 @@ class Annotation(Config): > m = re.match(r'.* policy<(.*?)>', line) > if m: > match = True > - entry['policy'] |= literal_eval(m.group(1)) > + try: > + entry['policy'] |= literal_eval(m.group(1)) > + except TypeError: > + entry['policy'] = {**entry['policy'], > **literal_eval(m.group(1))} > > m = re.match(r'.* note<(.*?)>', line) > if m: > @@ -204,7 +207,10 @@ class Annotation(Config): > # Determine if we need to import all configs or a single config > if not configs: > configs = c.config.keys() > - configs |= self.search_config(arch=arch, > flavour=flavour).keys() > + try: > + configs |= self.search_config(arch=arch, > flavour=flavour).keys() > + except TypeError: > + configs = {**configs, **self.search_config(arch=arch, > flavour=flavour).keys()} > > # Import configs from the Kconfig object into Annotations > if flavour is not None: > @@ -335,8 +341,12 @@ class Annotation(Config): > # If new_val is a subset of old_val, skip it > old_val = tmp_a.config.get(conf) > if old_val and 'policy' in old_val: > - if old_val['policy'] == old_val['policy'] | > new_val['policy']: > - continue > + try: > + if old_val['policy'] == old_val['policy'] | > new_val['policy']: > + continue > + except TypeError: > + if old_val['policy'] == {**old_val['policy'], > **new_val['policy']}: > + continue > > # Write out the policy (and note) line(s) > val = dict(sorted(new_val['policy'].items())) > -- > 2.39.2 > > > -- > kernel-team mailing list > kernel-team@lists.ubuntu.com > https://lists.ubuntu.com/mailman/listinfo/kernel-team >
diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py index dcc133dbbf62..b521bd0c7135 100644 --- a/debian/scripts/misc/kconfig/annotations.py +++ b/debian/scripts/misc/kconfig/annotations.py @@ -105,7 +105,10 @@ class Annotation(Config): m = re.match(r'.* policy<(.*?)>', line) if m: match = True - entry['policy'] |= literal_eval(m.group(1)) + try: + entry['policy'] |= literal_eval(m.group(1)) + except TypeError: + entry['policy'] = {**entry['policy'], **literal_eval(m.group(1))} m = re.match(r'.* note<(.*?)>', line) if m: @@ -204,7 +207,10 @@ class Annotation(Config): # Determine if we need to import all configs or a single config if not configs: configs = c.config.keys() - configs |= self.search_config(arch=arch, flavour=flavour).keys() + try: + configs |= self.search_config(arch=arch, flavour=flavour).keys() + except TypeError: + configs = {**configs, **self.search_config(arch=arch, flavour=flavour).keys()} # Import configs from the Kconfig object into Annotations if flavour is not None: @@ -335,8 +341,12 @@ class Annotation(Config): # If new_val is a subset of old_val, skip it old_val = tmp_a.config.get(conf) if old_val and 'policy' in old_val: - if old_val['policy'] == old_val['policy'] | new_val['policy']: - continue + try: + if old_val['policy'] == old_val['policy'] | new_val['policy']: + continue + except TypeError: + if old_val['policy'] == {**old_val['policy'], **new_val['policy']}: + continue # Write out the policy (and note) line(s) val = dict(sorted(new_val['policy'].items()))