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')
|
subdir = data.get('subdir')
|
||||||
aliases = data.get('aliases')
|
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.__init__(class_name, package, config, subdir, aliases)
|
||||||
self._extra_dirs = data.get('_extra_dirs', [])
|
self._extra_dirs = data.get('_extra_dirs', [])
|
||||||
self._searched_paths = data.get('_searched_paths', set())
|
self._searched_paths = data.get('_searched_paths', set())
|
||||||
|
@ -105,6 +108,8 @@ class PluginLoader:
|
||||||
aliases = self.aliases,
|
aliases = self.aliases,
|
||||||
_extra_dirs = self._extra_dirs,
|
_extra_dirs = self._extra_dirs,
|
||||||
_searched_paths = self._searched_paths,
|
_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):
|
def print_paths(self):
|
||||||
|
@ -258,11 +263,13 @@ class PluginLoader:
|
||||||
path = self.find_plugin(name)
|
path = self.find_plugin(name)
|
||||||
if path is None:
|
if path is None:
|
||||||
return 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:
|
if path not in self._module_cache:
|
||||||
self._module_cache[path] = imp.load_source('.'.join([self.package, name]), path)
|
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)
|
return getattr(self._module_cache[path], self.class_name)(*args, **kwargs)
|
||||||
|
|
||||||
def all(self, *args, **kwargs):
|
def all(self, *args, **kwargs):
|
||||||
|
@ -275,12 +282,15 @@ class PluginLoader:
|
||||||
name, ext = os.path.splitext(os.path.basename(path))
|
name, ext = os.path.splitext(os.path.basename(path))
|
||||||
if name.startswith("_"):
|
if name.startswith("_"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if path not in self._module_cache:
|
if path not in self._module_cache:
|
||||||
self._module_cache[path] = imp.load_source('.'.join([self.package, name]), path)
|
self._module_cache[path] = imp.load_source('.'.join([self.package, name]), path)
|
||||||
|
|
||||||
if kwargs.get('class_only', False):
|
if kwargs.get('class_only', False):
|
||||||
obj = getattr(self._module_cache[path], self.class_name)
|
obj = getattr(self._module_cache[path], self.class_name)
|
||||||
else:
|
else:
|
||||||
obj = getattr(self._module_cache[path], self.class_name)(*args, **kwargs)
|
obj = getattr(self._module_cache[path], self.class_name)(*args, **kwargs)
|
||||||
|
|
||||||
# set extra info on the module, in case we want it later
|
# set extra info on the module, in case we want it later
|
||||||
setattr(obj, '_original_path', path)
|
setattr(obj, '_original_path', path)
|
||||||
yield obj
|
yield obj
|
||||||
|
|
Loading…
Reference in a new issue