From 7175d05335dbed0dde0e06d5de19954b6ca47042 Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Sep 01 2014 12:15:20 +0000 Subject: plugin_registry vs. protocol(s): "kludge" -> fixed feature In fact, commit 8dd14ec29fe829e9edf0102e45966a4a1cc012d7 commented out what was intentionally present to prevent RuntimeWarning due to importing discovered plugins to the yet non-existent module namespace (missing parent) in case the respective registry hadn't been imported in advance. That commit tried to solve a conflict with protol.py, which referred to "clufter.plugins" module namespace, but unlike the previous registries (formats, filters, commands), "plugins" is not backed by a real module (i.e., neither plugins.py nor plugins/__init__.py exist at the top level). Solution is simple, make protocols registry set the namespace as a non-value, which is then considered a signal not to attempt any such for-the-sake-of-sanity complementary import. Signed-off-by: Jan Pokorný --- diff --git a/plugin_registry.py b/plugin_registry.py index f2e5e5b..217c1bf 100644 --- a/plugin_registry.py +++ b/plugin_registry.py @@ -58,9 +58,11 @@ class PluginRegistry(type): # (e.g., specific plugin was imported natively) registry.setup() PluginRegistry._registries.add(registry) - #if registry.namespace not in modules: - # # XXX hack to keep going in the test suite - # __import__(registry.namespace) + # rely on __builtin__ being always present, hence failing test + if (registry.namespace or '__builtin__') not in modules: + # XXX hack to prevent RuntimeWarning due to missing parent + # module (e.g., some tests in the test suite) + __import__(registry.namespace) ret = super(PluginRegistry, registry).__new__(registry, name, bases, attrs) diff --git a/protocol.py b/protocol.py index 54c81d4..ed0f546 100644 --- a/protocol.py +++ b/protocol.py @@ -22,6 +22,8 @@ class protocols(PluginRegistry): in-code documentation of their usage as opposed to much further in the processing with some files already successfully produced, etc. """ + _namespace = '' # avoid the plugins module-import namespace, unused anyway + @classmethod def register(registry, pr): # undecor to pass the checks in probe