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

Feat(plugins): Add strict mode and ignore_case flags to natural_sort filter #4298

Merged
merged 8 commits into from
Aug 2, 2024

Conversation

gmuloc
Copy link
Contributor

@gmuloc gmuloc commented Jul 31, 2024

Change Summary

This PR adds two new flags to the natural_sort filter

  1. a strict flag to be able to raise when the sort_key is missing in one item in the iterable dict or Namespace (default is False for backward compatibility).
  2. a ignore_case flag to be able to not ignore the case. Today natural_sort calls lower by default on some strings and this leads to AVD generating config not in the same order as EOS which does not use lower.

Related Issue(s)

Fixes #4242

Component(s) name

plugins

Proposed changes

Adding two flags to the function, with backward compatible default values to avoid impacting the rest of AVD
The goal is then to review the config ordering we have today against EOS and to use the flags where appropriate.

How to test

pytests have been added

Checklist

Note to reviewers

  • ignore_case: False for a list of string effectively reimplements builtin sort from Jinja -> is it worth it?

Repository Checklist

  • My code has been rebased from devel before I start
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and documentation have been updated accordingly.
  • I have updated molecule CI testing accordingly. (check the box if not applicable)

@gmuloc gmuloc requested review from a team as code owners July 31, 2024 09:44
Copy link

Review docs on Read the Docs

To test this pull request:

# Create virtual environment for this testing below the current directory
python -m venv test-avd-pr-4298
# Activate the virtual environment
source test-avd-pr-4298/bin/activate
# Install all requirements including PyAVD
pip install "pyavd[ansible] @ git+https://github.com/gmuloc/avd.git@natural-sort-upgrade#subdirectory=python-avd" --force
# Point Ansible collections path to the Python virtual environment
export ANSIBLE_COLLECTIONS_PATH=$VIRTUAL_ENV/ansible_collections
# Install Ansible collection
ansible-galaxy collection install git+https://github.com/gmuloc/avd.git#/ansible_collections/arista/avd/,natural-sort-upgrade --force
# Optional: Install AVD examples
cd test-avd-pr-4298
ansible-playbook arista.avd.install_examples

@gmuloc gmuloc added this to the v5.0.0-dev1 milestone Jul 31, 2024
Copy link
Contributor

@ClausHolbechArista ClausHolbechArista left a comment

Choose a reason for hiding this comment

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

approved by mistake

@github-actions github-actions bot added type: documentation Improvements or additions to documentation filter: natural_sort issue related to natural_sort filter plugin type: Python filters labels Jul 31, 2024
@ClausHolbechArista
Copy link
Contributor

The special catch in the template of hardware_counters should be removed in 5.0.0. The negative test of that is causing the tests here to fail.

@github-actions github-actions bot added the state: CI Updated CI scenario have been updated in the PR label Jul 31, 2024
@gmuloc gmuloc requested review from a team July 31, 2024 15:11
@github-actions github-actions bot added the state: conflict PR with conflict label Aug 2, 2024
Copy link

github-actions bot commented Aug 2, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the state: conflict PR with conflict label Aug 2, 2024
Copy link

github-actions bot commented Aug 2, 2024

Conflicts have been resolved. A maintainer will review the pull request shortly.

@github-actions github-actions bot removed the state: CI Updated CI scenario have been updated in the PR label Aug 2, 2024
@ClausHolbechArista ClausHolbechArista added the one approval This PR has one approval and is only missing one more. label Aug 2, 2024
@ClausHolbechArista ClausHolbechArista requested a review from a team August 2, 2024 13:55
Copy link
Member

@carlbuchmann carlbuchmann left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

sonarcloud bot commented Aug 2, 2024

@gmuloc gmuloc merged commit 9decee1 into aristanetworks:devel Aug 2, 2024
43 checks passed
jrecchia1029 pushed a commit to jrecchia1029/ansible-avd that referenced this pull request Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filter: natural_sort issue related to natural_sort filter plugin one approval This PR has one approval and is only missing one more. rn: Feat(plugins) type: documentation Improvements or additions to documentation type: Python filters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat(plugins): Allow natural_sort to be case sensitive for strings
3 participants