Skip to content

Commit

Permalink
Use PluginPathContext objects in PluginLoader._plugin_path_cache inst…
Browse files Browse the repository at this point in the history
…ead of tuples.
  • Loading branch information
felixfontein committed Jul 10, 2020
1 parent cbf8894 commit 035a146
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/ansible/plugins/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,10 @@ def _find_plugin_legacy(self, name, plugin_load_context, ignore_deprecated=False
# requested mod_type
pull_cache = self._plugin_path_cache[suffix]
try:
path, collection = pull_cache[name]
plugin_load_context.plugin_resolved_path = path
path_with_context = pull_cache[name]
plugin_load_context.plugin_resolved_path = path_with_context.path
plugin_load_context.plugin_resolved_name = name
plugin_load_context.plugin_resolved_collection = collection
plugin_load_context.plugin_resolved_collection = 'ansible.builtin' if path_with_context.internal else ''
plugin_load_context.resolved = True
return plugin_load_context
except KeyError:
Expand Down Expand Up @@ -677,31 +677,31 @@ def _find_plugin_legacy(self, name, plugin_load_context, ignore_deprecated=False

splitname = os.path.splitext(full_name)
base_name = splitname[0]
collection = 'ansible.builtin' if path_context.internal else ''
internal = path_context.internal
try:
extension = splitname[1]
except IndexError:
extension = ''

# Module found, now enter it into the caches that match this file
if base_name not in self._plugin_path_cache['']:
self._plugin_path_cache[''][base_name] = (full_path, collection)
self._plugin_path_cache[''][base_name] = PluginPathContext(full_path, internal)

if full_name not in self._plugin_path_cache['']:
self._plugin_path_cache[''][full_name] = (full_path, collection)
self._plugin_path_cache[''][full_name] = PluginPathContext(full_path, internal)

if base_name not in self._plugin_path_cache[extension]:
self._plugin_path_cache[extension][base_name] = (full_path, collection)
self._plugin_path_cache[extension][base_name] = PluginPathContext(full_path, internal)

if full_name not in self._plugin_path_cache[extension]:
self._plugin_path_cache[extension][full_name] = (full_path, collection)
self._plugin_path_cache[extension][full_name] = PluginPathContext(full_path, internal)

self._searched_paths.add(path)
try:
path, collection = pull_cache[name]
plugin_load_context.plugin_resolved_path = path
path_with_context = pull_cache[name]
plugin_load_context.plugin_resolved_path = path_with_context.path
plugin_load_context.plugin_resolved_name = name
plugin_load_context.plugin_resolved_collection = collection
plugin_load_context.plugin_resolved_collection = 'ansible.builtin' if path_with_context.internal else ''
plugin_load_context.resolved = True
return plugin_load_context
except KeyError:
Expand All @@ -713,14 +713,14 @@ def _find_plugin_legacy(self, name, plugin_load_context, ignore_deprecated=False
alias_name = '_' + name
# We've already cached all the paths at this point
if alias_name in pull_cache:
path, collection = pull_cache[alias_name]
if not ignore_deprecated and not os.path.islink(path):
path_with_context = pull_cache[alias_name]
if not ignore_deprecated and not os.path.islink(path_with_context.path):
# FIXME: this is not always the case, some are just aliases
display.deprecated('%s is kept for backwards compatibility but usage is discouraged. ' # pylint: disable=ansible-deprecated-no-version
'The module documentation details page may explain more about this rationale.' % name.lstrip('_'))
plugin_load_context.plugin_resolved_path = path
plugin_load_context.plugin_resolved_path = path_with_context.path
plugin_load_context.plugin_resolved_name = alias_name
plugin_load_context.plugin_resolved_collection = collection
plugin_load_context.plugin_resolved_collection = 'ansible.builtin' if path_with_context.internal else ''
plugin_load_context.resolved = True
return plugin_load_context

Expand Down

0 comments on commit 035a146

Please sign in to comment.