Skip to contentSkip to conversation

[2.18][wrynose][PATCH] ast: Make PyLibNode support submodules in BBIMPORTS

PATCH Peter Kjellerstedt 1 participant 1 message Sep 24

lore
Share & tools
lore
#0 lore raw

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.

---
 lib/bb/parse/ast.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/bb/parse/ast.py +3 -2
index e23ef6db3..a9cfe75c3 100644
@@ -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):