mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Fix loader for filters (#37748)
* Fix loading of filter and test plugins
Filter and test plugins are different than other plugins in that they
can have many plugins in a single file. Therefore they need to operate
a little differently. They need to have all of the potential files
returned. Then the caller takes care of passing those onto jinja2 in
order for jinja2 to make use of them.
This problem was (most recently) introduced with f921369445
This commit also restructures how we deduplicate plugins to take paths
into account. If we want to start scoping which set of modules are
loaded (due to roles, for instance) we'll need to hang on to the path
information.
* add integration test for override
* Fix style checks for bcoca code
* Implement jinja2 plugin loader as a subclass
Having a subclass allows us to customize the overriding of jinja
plugins. We can then move common parts of common code into the Loader.
This commit is contained in:
parent
e501134755
commit
0633f73faf
8 changed files with 174 additions and 26 deletions
|
@ -300,16 +300,15 @@ class Templar:
|
|||
if self._filters is not None:
|
||||
return self._filters.copy()
|
||||
|
||||
plugins = [x for x in self._filter_loader.all()]
|
||||
|
||||
self._filters = dict()
|
||||
for fp in plugins:
|
||||
self._filters.update(fp.filters())
|
||||
|
||||
# TODO: Remove registering tests as filters in 2.9
|
||||
for name, func in self._get_tests().items():
|
||||
self._filters[name] = tests_as_filters_warning(name, func)
|
||||
|
||||
for fp in self._filter_loader.all():
|
||||
self._filters.update(fp.filters())
|
||||
|
||||
return self._filters.copy()
|
||||
|
||||
def _get_tests(self):
|
||||
|
@ -320,10 +319,8 @@ class Templar:
|
|||
if self._tests is not None:
|
||||
return self._tests.copy()
|
||||
|
||||
plugins = [x for x in self._test_loader.all()]
|
||||
|
||||
self._tests = dict()
|
||||
for fp in plugins:
|
||||
for fp in self._test_loader.all():
|
||||
self._tests.update(fp.tests())
|
||||
|
||||
return self._tests.copy()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue