summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/__init__.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/__init__.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/__init__.py')
-rw-r--r--bitbake/lib/bb/parse/__init__.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/bitbake/lib/bb/parse/__init__.py b/bitbake/lib/bb/parse/__init__.py
index 347609513b..4cd82f115b 100644
--- a/bitbake/lib/bb/parse/__init__.py
+++ b/bitbake/lib/bb/parse/__init__.py
@@ -99,12 +99,12 @@ def supports(fn, data):
99 return 1 99 return 1
100 return 0 100 return 0
101 101
102def handle(fn, data, include = 0): 102def handle(fn, data, include=0, baseconfig=False):
103 """Call the handler that is appropriate for this file""" 103 """Call the handler that is appropriate for this file"""
104 for h in handlers: 104 for h in handlers:
105 if h['supports'](fn, data): 105 if h['supports'](fn, data):
106 with data.inchistory.include(fn): 106 with data.inchistory.include(fn):
107 return h['handle'](fn, data, include) 107 return h['handle'](fn, data, include, baseconfig)
108 raise ParseError("not a BitBake file", fn) 108 raise ParseError("not a BitBake file", fn)
109 109
110def init(fn, data): 110def init(fn, data):