Skip to content
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

Merged
merged 5 commits into from Jan 19, 2017

Conversation

sivel
Copy link
Member

@sivel sivel commented Jan 17, 2017

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

plugins/filters/core.py

ANSIBLE VERSION
v2.3
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 jinja2 groupby 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.

@sivel
Copy link
Member Author

sivel commented Jan 17, 2017

This was submitted per request by @jimi-c

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bugfix_pull_request c:plugins/filter needs_triage Needs a first human triage before being processed. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 17, 2017
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -e
Copy link
Member

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).

Copy link
Member Author

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running which pythonfollowing this might be a good idea. It will make it easy to see the correct python is in use.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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 ]
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

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.

@gundalow gundalow requested a review from jimi-c January 18, 2017 14:44
@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label Jan 18, 2017
@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Jan 18, 2017
@abadger abadger merged commit 537b3b7 into ansible:devel Jan 19, 2017
abadger pushed a commit that referenced this pull request Jan 19, 2017
…20098 (#20362)

* Add jinja2 groupby filter override to cast namedtuple to tuple. Fixes #20098

* Address some of the requested changes

* Quoting

* Print the python path and version

* Be less explicitly verbose, rely on implicit verbosity
@abadger
Copy link
Contributor

abadger commented Jan 19, 2017

Merged to devel and cherry-picked (minus tests) to the stable-2.2 branch.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 5, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. c:plugins/filter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants