New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add jinja2 groupby filter override to cast namedtuple to tuple. Fixes #20098 #20362
Conversation
This was submitted per request by @jimi-c |
@@ -0,0 +1,28 @@ | |||
#!/usr/bin/env bash | |||
|
|||
set -e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use set -eux
here. This will catch use of undefined variables and will make it easier to see what's going on when the test runs (particularly handy when reading Shippable logs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I cannot use -u
, I had that there originally. It results in a failure when attempting to activate a virtualenv, with the following error:
bash: _OLD_VIRTUAL_PATH: unbound variable
There is apparently a long history as documented at pypa/virtualenv#150
I started to try defining the missing vars, and stopped at 5 variables.
|
||
virtualenv --system-site-packages $PYTHON "${MYTMPDIR}/jinja2" | ||
|
||
source "${MYTMPDIR}/jinja2/bin/activate" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running which python
following this might be a good idea. It will make it easy to see the correct python is in use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it another shot. I had it there, but it remember it failing on the osx build, which selected a different python than the venv that is used in the tests. Just not setting --python
in virtualenv seemed to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry I wasn't clear. I didn't mean to change how you're selecting the python version. I just meant that it would be good to run which python
after activating the venv, so it was clear which python was now used.
I actually need to improve ansible-test
a bit in this area, as using which python
has some odd behavior with the --python
option, but that's something I'll deal with later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is more my mistake for reading your comments on my phone. I've restored my original logic, and applied what you were referencing.
|
||
pip install -U jinja2==2.9.4 | ||
|
||
ansible-playbook -i ../../inventory test_jinja2_groupby.yml -v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding "$@"
at the end of this (and the following) call to ansible-playbook
will allow increasing verbosity of the output by passing in additional args.
|
||
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir') | ||
|
||
if [ -f /usr/bin/python3 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide a comment explaining why this is needed?
#!/usr/bin/env bash | ||
|
||
# We don't set -u here, due to pypa/virtualenv#150 | ||
set -e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like -x
got dropped with the last changes. On a side-note, if you use -x
, you don't need to be so verbose with the messaging about the python version below, since the commands are all shown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would suffice with -x
enabled:
which python
python -V
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my life apparently revolves around food, and I pushed before I was ready so I could eat dinner. The recent update should restore -x
and remove some explicit verbosity in my printing.
Merged to devel and cherry-picked (minus tests) to the stable-2.2 branch. |
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
plugins/filters/core.py
ANSIBLE VERSION
SUMMARY
On the heels of #20098, it was decided that we wanted a solution for people who didn't have access to jinja2<2.9 and while jinja2==2.9.5 was not yet released.
This PR overrides the
groupby
filter from jinja2, calls the jinja2groupby
filter, and casts the elements of the return to tuples.Based on jinja2<2.9 I have established what the return looked like as a repr, and ensured that the fix for 2.9.4 matches.