summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/parse_py/BBHandler.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-27 17:08:04 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-08 11:15:47 +0000
commit42e8b2682f56f450c1258956213198052d6bcb96 (patch)
tree6e1e223a179f5df5651fe3742b0e8afa55339597 /bitbake/lib/bb/parse/parse_py/BBHandler.py
parentf4ffba353eb7877060c25d264fa10cd60f797f0b (diff)
downloadpoky-42e8b2682f56f450c1258956213198052d6bcb96.tar.gz
bitbake: parse: Add support for addpylib conf file directive and BB_GLOBAL_PYMODULES
For many years OE-Core has injected it's own python modules into the python namespace using an immediate expansion of a variable in base.bbclass. It also added all entries from BBPATH to sys.path. We really need this to become a first class citizen of the langauge, this new addpylib directive allows that. Usage is of the form: addpylib <directory> <namespace> The namespace is imported and if there is an attribute BBIMPORT, that list of names is iterated and imported too. This mirrors what OE-Core has done for a long time with one difference in implmentation, sys.path is only appended to. This means later imported namespaces can't overwrite an earlier one and can't overwrite the main python module space. In practice we've never done that and it isn't something we should encourage or support. The new directive is only applied for .conf files and not other filetypes as it only makes sense in that context. It is also only allowed in the "base configuration" context of cookerdata since adding it at the recipe level wouldn't work properly due to the way it changes the global namespace. At the same time, move the list of modules to place in the global namespace into a BB_GLOBAL_PYMODULES variable. It is intended that only the core layer should touch this and it is meant to be a very small list, usually os and sys. BB_GLOBAL_PYMODULES is expected to be set before the first addpylib directive. Layers adding a lib directory will now need to use this directive as BBPATH is not going to be added automatically by OE-Core in future. The directives are immediate operations so it does make modules available sooner than the current OE-Core approach. The new code appends to sys.path rather than prepends as core did, as overwriting python standard library modules would be a bad idea and naturally encouraging people to collaborate around our own core modules is desireable. (Bitbake rev: afb8478d3853f6edf3669b93588314627d617d6b) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/parse/parse_py/BBHandler.py')
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index 584966fea1..4d5b45e1ef 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -101,7 +101,7 @@ def get_statements(filename, absolute_filename, base_name):
101 cached_statements[absolute_filename] = statements 101 cached_statements[absolute_filename] = statements
102 return statements 102 return statements
103 103
104def handle(fn, d, include): 104def handle(fn, d, include, baseconfig=False):
105 global __infunc__, __body__, __residue__, __classname__ 105 global __infunc__, __body__, __residue__, __classname__
106 __body__ = [] 106 __body__ = []
107 __infunc__ = [] 107 __infunc__ = []
@@ -265,7 +265,7 @@ def feeder(lineno, s, fn, root, statements, eof=False):
265 ast.handleInherit(statements, fn, lineno, m) 265 ast.handleInherit(statements, fn, lineno, m)
266 return 266 return
267 267
268 return ConfHandler.feeder(lineno, s, fn, statements) 268 return ConfHandler.feeder(lineno, s, fn, statements, conffile=False)
269 269
270# Add us to the handlers list 270# Add us to the handlers list
271from .. import handlers 271from .. import handlers