From 0fc187893dacea871fcaeba2c2d3d78ac1ae09fd Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 10 Nov 2015 11:25:07 -0500 Subject: [PATCH] Catch import warnings in a common location for both get() and all() Potential solution for #12979 --- lib/ansible/plugins/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py index 91b7bc3fa1..87de300e3c 100644 --- a/lib/ansible/plugins/__init__.py +++ b/lib/ansible/plugins/__init__.py @@ -307,8 +307,10 @@ class PluginLoader: if name in sys.modules: # See https://github.com/ansible/ansible/issues/13110 return sys.modules[name] - with open(path, 'r') as module_file: - module = imp.load_source(name, path, module_file) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RuntimeWarning) + with open(path, 'r') as module_file: + module = imp.load_source(name, path, module_file) return module def get(self, name, *args, **kwargs): @@ -344,9 +346,7 @@ class PluginLoader: continue if path not in self._module_cache: - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RuntimeWarning) - self._module_cache[path] = self._load_module_source(name, path) + self._module_cache[path] = self._load_module_source(name, path) if kwargs.get('class_only', False): obj = getattr(self._module_cache[path], self.class_name)