From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: chris.laplante@agilent.com
Cc: bitbake-devel@lists.openembedded.org
Subject: Re: [bitbake-devel] [PATCH 2/3] codeparser/utils: clean up more deprecated AST usages
Date: Sat, 21 Oct 2023 01:29:15 +0200 [thread overview]
Message-ID: <20231020232915d8ce06bb@mail.local> (raw)
In-Reply-To: <20231020184459.1420806-2-chris.laplante@agilent.com>
Traceback (most recent call last):
File "/home/pokybuild/yocto-worker/musl-qemux86/build/bitbake/bin/bitbake", line 21, in <module>
import bb
File "/home/pokybuild/yocto-worker/musl-qemux86/build/bitbake/lib/bb/__init__.py", line 137, in <module>
import bb.msg
File "/home/pokybuild/yocto-worker/musl-qemux86/build/bitbake/lib/bb/msg.py", line 20, in <module>
import bb.event
File "/home/pokybuild/yocto-worker/musl-qemux86/build/bitbake/lib/bb/event.py", line 23, in <module>
import bb.utils
File "/home/pokybuild/yocto-worker/musl-qemux86/build/bitbake/lib/bb/utils.py", line 1868, in <module>
def ast_node_str_value(node: ast.AST) -> str | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
On 20/10/2023 14:44:58-0400, Chris Laplante via lists.openembedded.org wrote:
> From: Chris Laplante <chris.laplante@agilent.com>
>
> Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
> ---
> lib/bb/codeparser.py | 22 ++++++++++------------
> lib/bb/utils.py | 9 +++++++++
> 2 files changed, 19 insertions(+), 12 deletions(-)
>
> diff --git a/lib/bb/codeparser.py b/lib/bb/codeparser.py
> index cd39409434..92ed31fa5f 100644
> --- a/lib/bb/codeparser.py
> +++ b/lib/bb/codeparser.py
> @@ -256,19 +256,18 @@ class PythonParser():
> def visit_Call(self, node):
> name = self.called_node_name(node.func)
> if name and (name.endswith(self.getvars) or name.endswith(self.getvarflags) or name in self.containsfuncs or name in self.containsanyfuncs):
> - if isinstance(node.args[0], ast.Constant) and isinstance(node.args[0].value, str):
> - varname = node.args[0].value
> - if name in self.containsfuncs and isinstance(node.args[1], ast.Str):
> + if (varname := bb.utils.ast_node_str_value(node.args[0])) is not None:
> + if name in self.containsfuncs and bb.utils.ast_node_str_value(node.args[1]) is not None:
> if varname not in self.contains:
> self.contains[varname] = set()
> - self.contains[varname].add(node.args[1].s)
> - elif name in self.containsanyfuncs and isinstance(node.args[1], ast.Str):
> + self.contains[varname].add(node.args[1].value)
> + elif name in self.containsanyfuncs and bb.utils.ast_node_str_value(node.args[1]) is not None:
> if varname not in self.contains:
> self.contains[varname] = set()
> - self.contains[varname].update(node.args[1].s.split())
> + self.contains[varname].update(node.args[1].value.split())
> elif name.endswith(self.getvarflags):
> - if isinstance(node.args[1], ast.Str):
> - self.references.add('%s[%s]' % (varname, node.args[1].s))
> + if bb.utils.ast_node_str_value(node.args[1]) is not None:
> + self.references.add('%s[%s]' % (varname, node.args[1].value))
> else:
> self.warn(node.func, node.args[1])
> else:
> @@ -276,8 +275,7 @@ class PythonParser():
> else:
> self.warn(node.func, node.args[0])
> elif name and name.endswith(".expand"):
> - if isinstance(node.args[0], ast.Str):
> - value = node.args[0].s
> + if (value := bb.utils.ast_node_str_value(node.args[0])) is not None:
> d = bb.data.init()
> parser = d.expandWithRefs(value, self.name)
> self.references |= parser.references
> @@ -287,8 +285,8 @@ class PythonParser():
> self.contains[varname] = set()
> self.contains[varname] |= parser.contains[varname]
> elif name in self.execfuncs:
> - if isinstance(node.args[0], ast.Str):
> - self.var_execs.add(node.args[0].s)
> + if bb.utils.ast_node_str_value(node.args[0]) is not None:
> + self.var_execs.add(node.args[0].value)
> else:
> self.warn(node.func, node.args[0])
> elif name and isinstance(node.func, (ast.Name, ast.Attribute)):
> diff --git a/lib/bb/utils.py b/lib/bb/utils.py
> index b401fa5ec7..55f8231999 100644
> --- a/lib/bb/utils.py
> +++ b/lib/bb/utils.py
> @@ -11,6 +11,7 @@ import re, fcntl, os, string, stat, shutil, time
> import sys
> import errno
> import logging
> +import ast
> import bb
> import bb.msg
> import locale
> @@ -1863,3 +1864,11 @@ def lock_timeout(lock):
> yield held
> finally:
> lock.release()
> +
> +def ast_node_str_value(node: ast.AST) -> str | None:
> + """
> + Returns node value if it is an `ast.Constant` str; None otherwise
> + """
> + if isinstance(node, ast.Constant) and isinstance(node.value, str):
> + return node.value
> + return None
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#15270): https://lists.openembedded.org/g/bitbake-devel/message/15270
> Mute This Topic: https://lists.openembedded.org/mt/102087479/3617179
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [alexandre.belloni@bootlin.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2023-10-20 23:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 18:44 [PATCH 1/3] codeparser: add missing 'import os' chris.laplante
2023-10-20 18:44 ` [PATCH 2/3] codeparser/utils: clean up more deprecated AST usages chris.laplante
2023-10-20 23:29 ` Alexandre Belloni [this message]
2023-10-23 15:02 ` [bitbake-devel] " chris.laplante
2023-10-20 18:44 ` [PATCH 3/3] codegen: cleanup " chris.laplante
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=20231020232915d8ce06bb@mail.local \
--to=alexandre.belloni@bootlin.com \
--cc=bitbake-devel@lists.openembedded.org \
--cc=chris.laplante@agilent.com \
/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.