ast: Make PyLibNode support submodules in BBIMPORTS
PATCH 1/1 ast: Make PyLibNode support submodules in BBIMPORTS
For a given addpylib <path> <namespace>, the existing code would import all modules specified in BBIMPORTS with the assumption that there are no submodules. This adds support for specifying submodules as well. E.g., BBIMPORTS = "foo.bar" will now make <namespace>.foo.bar available.
Signed-off-by Peter Kjellerstedt <[email protected]>
---
In theory, one could do addpylib <lib>/<namespace> foo and then use BBIMPORTS = "bar". However, any existing import <namespace>.foo.bar in the code would not match the import made via BBIMPORTS.
lib/bb/parse/ast.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/bb/parse/ast.py +3 -2
@@ -310,8 +310,9 @@ class PyLibNode(AstNode): bb.utils._context[self.namespace] = __import__(self.namespace) toimport = getattr(bb.utils._context[self.namespace], "BBIMPORTS", []) for i in toimport: - bb.utils._context[self.namespace] = __import__(self.namespace + "." + i) - mod = getattr(bb.utils._context[self.namespace], i) + mod = bb.utils._context[self.namespace] = __import__(self.namespace + "." + i) + for submod in i.split("."): + mod = getattr(mod, submod) fn = getattr(mod, "__file__") funcs = {} for f in dir(mod):