Skip to contentSkip to conversation

Load devtool and reciptool plugins in a well-defined manner

PATCH In review Ola x Nilsson 3 participants 8 messages Oct 25, 2016 – Dec 8, 2016

lore
Share & tools
lore
#0 lore raw

cover Load devtool and reciptool plugins in a well-defined manner

From: Ola x Nilsson <[email protected]>

Make devtool and recipetool load plugins in a well-defined and expected manner.

devtool and reciptool search for pluings first in scripts/lib/<tool> and then in BBPATH. Each found plugin is loaded, which means that any plugin found later in BBPATH shadows previously loaded plugins. plugin_init is loaded for all plugins, no matter whether they are later replaced. register_plugin is called once for each time a plugin with a certain name is found, but it is always called on the last loaded plugin.

Change the scriptutils.load_plugins function to never load a plugin file if one with the same filename has already been loaded. This means that the first found plugin wins.

Change the load order to first search BBPATH and then scripts/lib/tools. This means that plugins in scripts/lib/<tool> can be shadowed by plugins in layers.

Ola x Nilsson (4):
devtool: selftest: add test for devtool plugin loading
recipetool: selftest: Add test for recipetool plugin loading
devtool: Load plugins in a well defined order
recipetool: Load plugins in a well defined order

 meta-selftest/lib/devtool/bbpath.py    | 44 ++++++++++++++++++++++++++++++++++
 meta-selftest/lib/recipetool/bbpath.py | 41 +++++++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/devtool.py      | 43 +++++++++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/recipetool.py   | 44 ++++++++++++++++++++++++++++++++++
 scripts/devtool                        |  3 ++-
 scripts/lib/scriptutils.py             |  8 +++++--
 scripts/recipetool                     |  4 ++--
 7 files changed, 182 insertions(+), 5 deletions(-)
 create mode 100644 meta-selftest/lib/devtool/bbpath.py
 create mode 100644 meta-selftest/lib/recipetool/bbpath.py
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/4 devtool: selftest: add test for devtool plugin loading

From: Ola x Nilsson <[email protected]>

Test that devtool plugins are loaded in a well defined order.

---
 meta-selftest/lib/devtool/bbpath.py | 44 +++++++++++++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/devtool.py   | 43 ++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 meta-selftest/lib/devtool/bbpath.py
meta-selftest/lib/devtool/bbpath.py new file +44 -0
new file mode 100644
index 0000000..5e8ffb3
@@ -0,0 +1,44 @@
+import argparse
+
+already_loaded = False
+kept_context = None
+
+def plugin_name(filename):
+    return os.path.splitext(os.path.basename(filename))[0]
+
+def plugin_init(plugins):
+    global already_loaded
+    already_loaded = plugin_name(__file__) in (plugin_name(p.__name__) for p in plugins)
+
+def print_name(args, config, basepath, workspace):
+    print (__file__)
+
+def print_bbdir(args, config, basepath, workspace):
+    print (__file__.replace('/lib/devtool/bbpath.py',''))
+
+def print_registered(args, config, basepath, workspace):
+    global kept_context
+    print(kept_context.loaded)
+
+def multiloaded(args, config, basepath, workspace):
+    global already_loaded
+    print("yes" if already_loaded else "no")
+
+def register_commands(subparsers, context):
+    global kept_context
+    kept_context = context
+    if 'loaded' in context.__dict__:
+        context.loaded += 1
+    else:
+        context.loaded = 1
+
+    def addparser(name, helptxt, func):
+        parser = subparsers.add_parser(name, help=helptxt,
+                                       formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+        parser.set_defaults(func=func)
+        return parser
+
+    addparser('pluginfile', 'Print the filename of this plugin', print_name)
+    addparser('bbdir', 'Print the BBPATH directory of this plugin', print_bbdir)
+    addparser('count', 'How many times have this plugin been registered.', print_registered)
+    addparser('multiloaded', 'How many times have this plugin been initialized', multiloaded)
meta/lib/oeqa/selftest/devtool.py +43 -0

49 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/4 recipetool: selftest: Add test for recipetool plugin loading

In reply to Ola x Nilsson

From: Ola x Nilsson <[email protected]>

Test that recipetool plugins are loaded in a well defined order.

---
 meta-selftest/lib/recipetool/bbpath.py | 41 +++++++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/recipetool.py   | 44 ++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)
 create mode 100644 meta-selftest/lib/recipetool/bbpath.py
meta-selftest/lib/recipetool/bbpath.py new file +41 -0
new file mode 100644
index 0000000..783b2dc
@@ -0,0 +1,41 @@
+import argparse
+
+already_loaded = False
+register_count = 0
+
+def plugin_name(filename):
+    return os.path.splitext(os.path.basename(filename))[0]
+
+def plugin_init(plugins):
+    global already_loaded
+    already_loaded = plugin_name(__file__) in (plugin_name(p.__name__) for p in plugins)
+
+def print_name(opts):
+    print (__file__)
+
+def print_bbdir(opts):
+    print (__file__.replace('/lib/recipetool/bbpath.py',''))
+
+def print_registered(opts):
+    #global kept_context
+    #print(kept_context.loaded)
+    print ("1")
+
+def multiloaded(opts):
+    global already_loaded
+    print("yes" if already_loaded else "no")
+
+def register_commands(subparsers):
+    global register_count
+    register_count += 1
+
+    def addparser(name, helptxt, func):
+        parser = subparsers.add_parser(name, help=helptxt,
+                                       formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+        parser.set_defaults(func=func)
+        return parser
+
+    addparser('pluginfile', 'Print the filename of this plugin', print_name)
+    addparser('bbdir', 'Print the BBPATH directory of this plugin', print_bbdir)
+    addparser('count', 'How many times have this plugin been registered.', print_registered)
+    addparser('multiloaded', 'How many times have this plugin been initialized', multiloaded)
meta/lib/oeqa/selftest/recipetool.py +44 -0

61 lines not on this page · raw message

Signature · 1 line
2.1.4
#3 lore raw

PATCH 3/4 devtool: Load plugins in a well defined order

In reply to Ola x Nilsson

From: Ola x Nilsson <[email protected]>

To allow devtool plugins in one layer to shadow another in a well defined way, first search BBPATH/lib/devtool directories and then scripts/lib/devool and load only the first found.

The previous search and load loop would load all found plugins with the ones found later replacing any found before.

---
 scripts/devtool            | 3 ++-
 scripts/lib/scriptutils.py | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
scripts/devtool +2 -1
index 0c32c50..2197493 100755
@@ -294,7 +294,8 @@ def main():
         finally:
             tinfoil.shutdown()
 
-    for path in [scripts_path] + global_args.bbpath.split(':'):
+    # Search BBPATH first to allow layers to override plugins in scripts_path
+    for path in global_args.bbpath.split(':') + [scripts_path]:
         pluginpath = os.path.join(path, 'lib', 'devtool')
         scriptutils.load_plugins(logger, plugins, pluginpath)
 
scripts/lib/scriptutils.py +6 -2
index 5ccc027..27d82b6 100644
@@ -52,10 +52,14 @@ def load_plugins(logger, plugins, pluginpath):
             if fp:
                 fp.close()
 
+    def plugin_name(filename):
+        return os.path.splitext(os.path.basename(filename))[0]
+
+    known_plugins = [plugin_name(p.__name__) for p in plugins]
     logger.debug('Loading plugins from %s...' % pluginpath)
     for fn in glob.glob(os.path.join(pluginpath, '*.py')):
-        name = os.path.splitext(os.path.basename(fn))[0]
-        if name != '__init__':
+        name = plugin_name(fn)
+        if name != '__init__' and name not in known_plugins:
             plugin = load_plugin(name)
             if hasattr(plugin, 'plugin_init'):
                 plugin.plugin_init(plugins)
Signature · 1 line
2.1.4
#4 lore raw

PATCH 4/4 recipetool: Load plugins in a well defined order

In reply to Ola x Nilsson

From: Ola x Nilsson <[email protected]>

To allow recipetool plugins in one layer to shadow another in a well defined way, first search BBPATH/lib/recipetool directories and then scripts/lib/recipetool and load only the first found.

The previous search and load loop would load all found plugins with the ones found later replacing any found before.

---
 scripts/recipetool | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/recipetool +2 -2
index 1052cd2..00c9007 100755
@@ -78,8 +78,8 @@ def main():
 
     tinfoil = tinfoil_init(False)
     try:
-        for path in ([scripts_path] +
-                    tinfoil.config_data.getVar('BBPATH', True).split(':')):
+        for path in (tinfoil.config_data.getVar('BBPATH', True).split(':')
+                     + [scripts_path]):
             pluginpath = os.path.join(path, 'lib', 'recipetool')
             scriptutils.load_plugins(logger, plugins, pluginpath)
 
Signature · 1 line
2.1.4
#5 lore raw
In reply to Ola x Nilsson

Ping?

Signature · 1 line
Ola x Nilsson
Quoted 49 lines

-----Original Message-----
From: Ola x Nilsson [mailto:[email protected]]
Sent: den 25 oktober 2016 13:04
To: Ola x Nilsson; [email protected]
Subject: [PATCH 0/4] Load devtool and reciptool plugins in a well-defined manner

From: Ola x Nilsson <[email protected]>

Make devtool and recipetool load plugins in a well-defined and expected manner.

devtool and reciptool search for pluings first in scripts/lib/<tool> and then in BBPATH. Each found plugin is loaded, which means that any plugin found later in BBPATH shadows previously loaded plugins.
plugin_init is loaded for all plugins, no matter whether they are later replaced. register_plugin is called once for each time a plugin with a certain name is found, but it is always called on the last loaded plugin.

Change the scriptutils.load_plugins function to never load a plugin file if one with the same filename has already been loaded. This means that the first found plugin wins.

Change the load order to first search BBPATH and then scripts/lib/tools. This means that plugins in scripts/lib/<tool> can be shadowed by plugins in layers.

Ola x Nilsson (4):
devtool: selftest: add test for devtool plugin loading
recipetool: selftest: Add test for recipetool plugin loading
devtool: Load plugins in a well defined order
recipetool: Load plugins in a well defined order

 meta-selftest/lib/devtool/bbpath.py    | 44
++++++++++++++++++++++++++++++++++
 meta-selftest/lib/recipetool/bbpath.py | 41
+++++++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/devtool.py      | 43
+++++++++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/recipetool.py   | 44
++++++++++++++++++++++++++++++++++
 scripts/devtool                        |  3 ++-
 scripts/lib/scriptutils.py             |  8 +++++--
 scripts/recipetool                     |  4 ++--
 7 files changed, 182 insertions(+), 5 deletions(-)  create mode 100644 meta-
selftest/lib/devtool/bbpath.py
 create mode 100644 meta-selftest/lib/recipetool/bbpath.py

--
2.1.4

Acked-by
#6 lore raw
Quoted 1 line · On Tue, 06 Dec 2016 07:37:16 Ola x Nilsson wrote:

Ping?

I guess Ross / Richard were waiting for my ack - sorry about that.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#7 lore raw

Sorry, slipped down in my inbox. Thanks for acking Paul, these are in staging now.

Ross

Quoted 20 lines · Paul Eggleton
Quoted 1 line · On Tue, 06 Dec 2016 07:37:16 Ola x Nilsson wrote:

Ping?

I guess Ross / Richard were waiting for my ack - sorry about that.

Cheers,
Paul

--

Paul Eggleton
Intel Open Source Technology Centre
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core