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 'duplicate' to the set theory filters #45396

Open
wants to merge 4 commits into
base: devel
from

Conversation

Projects
None yet
5 participants
@flatline-studios
Contributor

flatline-studios commented Sep 9, 2018

SUMMARY

'duplicate' will take a list of values, and return all duplicate values found within it, if any.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

duplicate

ANSIBLE VERSION
ansible 2.6.3
  config file = /var/ansible/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vagrant/.local/lib/python3.6/site-packages/ansible
  executable location = /home/vagrant/.local/bin/ansible
  python version = 3.6.5 (default, Apr  1 2018, 05:46:30) [GCC 7.3.0]
ADDITIONAL INFORMATION
- debug:
    msg: '{{ [1, 1, 1, 2, 3, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8] | duplicate }}'

...

MSG:

[1, 3, 8]
Add 'duplicate' to the set theory filters
'duplicate' will take a list of values, and return all duplicate values found within it, if any.
Fix Sanity check fail
Add extra line break after the duplicate function
@ansibot

This comment has been minimized.

Contributor

ansibot commented Sep 9, 2018

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/plugins/filter/mathstuff.py:64:1: E302 expected 2 blank lines, found 1

click here for bot help

@ansibot

This comment has been minimized.

Contributor

ansibot commented Sep 9, 2018

@ansibot ansibot added docs and removed needs_revision labels Sep 9, 2018

@@ -45,6 +45,23 @@ def unique(a):
return c
def duplicate(a):
if isinstance(a, collections.Hashable):
c = set(a)

This comment has been minimized.

@mkrizek

mkrizek Sep 10, 2018

Contributor

But this is unique no?

I'd also add tests.

This comment has been minimized.

@flatline-studios

flatline-studios Sep 10, 2018

Contributor

I'm by no means a python expert, but I think line 49 and 50 means, if the argument is a dictionary, then return it without alteration.

As dictionary's aren't hashable, but lists are, and this filter only operates on lists, then this check needs to be made.

As I say I could be wrong on this though.

Ill try and find some time later to knock up a few tests...

@ansibot

This comment has been minimized.

Contributor

ansibot commented Oct 20, 2018

@flatline-studios this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@acozine

This comment has been minimized.

Contributor

acozine commented Oct 20, 2018

@flatline-studios you'll need to rebase your branch (instead of merging the most recent devel branch into it) before our CI system will kick off a new test run.

@flatline-studios

This comment has been minimized.

Contributor

flatline-studios commented Oct 20, 2018

@flatline-studios you'll need to rebase your branch (instead of merging the most recent devel branch into it) before our CI system will kick off a new test run.

@acozine - I did (at least I thought I did). I followed the instructions at https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html, and pushed the changes back to my repo.

I'm new to git, so I don't quite understand what you mean to be honest.

@bcoca

This comment has been minimized.

Member

bcoca commented Oct 22, 2018

isn't this the same as:
list1|intersect(list2)|unique?
nvmd misread

@flatline-studios

This comment has been minimized.

Contributor

flatline-studios commented Oct 22, 2018

@ansibot ansibot added the stale_ci label Oct 31, 2018

@ansibot ansibot added the docsite label Dec 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment