mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix serialization bug for plugins (v2)
This commit is contained in:
parent
4f28a814ae
commit
1152c7327a
1 changed files with 20 additions and 10 deletions
|
@ -88,6 +88,9 @@ class PluginLoader:
|
|||
subdir = data.get('subdir')
|
||||
aliases = data.get('aliases')
|
||||
|
||||
PATH_CACHE[class_name] = data.get('PATH_CACHE')
|
||||
PLUGIN_PATH_CACHE[class_name] = data.get('PLUGIN_PATH_CACHE')
|
||||
|
||||
self.__init__(class_name, package, config, subdir, aliases)
|
||||
self._extra_dirs = data.get('_extra_dirs', [])
|
||||
self._searched_paths = data.get('_searched_paths', set())
|
||||
|
@ -105,6 +108,8 @@ class PluginLoader:
|
|||
aliases = self.aliases,
|
||||
_extra_dirs = self._extra_dirs,
|
||||
_searched_paths = self._searched_paths,
|
||||
PATH_CACHE = PATH_CACHE[self.class_name],
|
||||
PLUGIN_PATH_CACHE = PLUGIN_PATH_CACHE[self.class_name],
|
||||
)
|
||||
|
||||
def print_paths(self):
|
||||
|
@ -258,11 +263,13 @@ class PluginLoader:
|
|||
path = self.find_plugin(name)
|
||||
if path is None:
|
||||
return None
|
||||
elif kwargs.get('class_only', False):
|
||||
return getattr(self._module_cache[path], self.class_name)
|
||||
|
||||
if path not in self._module_cache:
|
||||
self._module_cache[path] = imp.load_source('.'.join([self.package, name]), path)
|
||||
|
||||
if kwargs.get('class_only', False):
|
||||
return getattr(self._module_cache[path], self.class_name)
|
||||
else:
|
||||
return getattr(self._module_cache[path], self.class_name)(*args, **kwargs)
|
||||
|
||||
def all(self, *args, **kwargs):
|
||||
|
@ -275,12 +282,15 @@ class PluginLoader:
|
|||
name, ext = os.path.splitext(os.path.basename(path))
|
||||
if name.startswith("_"):
|
||||
continue
|
||||
|
||||
if path not in self._module_cache:
|
||||
self._module_cache[path] = imp.load_source('.'.join([self.package, name]), path)
|
||||
|
||||
if kwargs.get('class_only', False):
|
||||
obj = getattr(self._module_cache[path], self.class_name)
|
||||
else:
|
||||
obj = getattr(self._module_cache[path], self.class_name)(*args, **kwargs)
|
||||
|
||||
# set extra info on the module, in case we want it later
|
||||
setattr(obj, '_original_path', path)
|
||||
yield obj
|
||||
|
|
Loading…
Reference in a new issue