mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Catch import warnings in a common location for both get() and all()
Potential solution for #12979
This commit is contained in:
parent
9f0c2cfda5
commit
0fc187893d
1 changed files with 5 additions and 5 deletions
|
@ -307,8 +307,10 @@ class PluginLoader:
|
||||||
if name in sys.modules:
|
if name in sys.modules:
|
||||||
# See https://github.com/ansible/ansible/issues/13110
|
# See https://github.com/ansible/ansible/issues/13110
|
||||||
return sys.modules[name]
|
return sys.modules[name]
|
||||||
with open(path, 'r') as module_file:
|
with warnings.catch_warnings():
|
||||||
module = imp.load_source(name, path, module_file)
|
warnings.simplefilter("ignore", RuntimeWarning)
|
||||||
|
with open(path, 'r') as module_file:
|
||||||
|
module = imp.load_source(name, path, module_file)
|
||||||
return module
|
return module
|
||||||
|
|
||||||
def get(self, name, *args, **kwargs):
|
def get(self, name, *args, **kwargs):
|
||||||
|
@ -344,9 +346,7 @@ class PluginLoader:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if path not in self._module_cache:
|
if path not in self._module_cache:
|
||||||
with warnings.catch_warnings():
|
self._module_cache[path] = self._load_module_source(name, path)
|
||||||
warnings.simplefilter("ignore", RuntimeWarning)
|
|
||||||
self._module_cache[path] = self._load_module_source(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)
|
||||||
|
|
Loading…
Reference in a new issue