[2.18][wrynose][PATCH] ast: Make PyLibNode support submodules in BBIMPORTS
From: Peter Kjellerstedt <[email protected]>
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]>
--- 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):