ensure prefix in plugin loading to avoid conflicts
when using 'all' to load all plugins were ending in main namespace creating conflicts with each other and random modulesr i.e. when trying to access json callback we were getting json 'parsing' lib
This commit is contained in:
parent
498bf4b5be
commit
b93b9e68d7
1 changed files with 10 additions and 5 deletions
|
@ -329,13 +329,18 @@ class PluginLoader:
|
||||||
__contains__ = has_plugin
|
__contains__ = has_plugin
|
||||||
|
|
||||||
def _load_module_source(self, name, path):
|
def _load_module_source(self, name, path):
|
||||||
if name in sys.modules:
|
|
||||||
# See https://github.com/ansible/ansible/issues/13110
|
# avoid collisions across plugins
|
||||||
return sys.modules[name]
|
full_name = '.'.join([self.package, name])
|
||||||
|
|
||||||
|
if full_name in sys.modules:
|
||||||
|
# Avoids double loading, See https://github.com/ansible/ansible/issues/13110
|
||||||
|
return sys.modules[full_name]
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore", RuntimeWarning)
|
warnings.simplefilter("ignore", RuntimeWarning)
|
||||||
with open(path, 'rb') as module_file:
|
with open(path, 'rb') as module_file:
|
||||||
module = imp.load_source(name, path, module_file)
|
module = imp.load_source(full_name, path, module_file)
|
||||||
return module
|
return module
|
||||||
|
|
||||||
def get(self, name, *args, **kwargs):
|
def get(self, name, *args, **kwargs):
|
||||||
|
@ -350,7 +355,7 @@ class PluginLoader:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if path not in self._module_cache:
|
if path not in self._module_cache:
|
||||||
self._module_cache[path] = self._load_module_source('.'.join([self.package, name]), path)
|
self._module_cache[path] = self._load_module_source(name, path)
|
||||||
found_in_cache = False
|
found_in_cache = False
|
||||||
|
|
||||||
obj = getattr(self._module_cache[path], self.class_name)
|
obj = getattr(self._module_cache[path], self.class_name)
|
||||||
|
|
Loading…
Reference in a new issue