From dc60e875ae83c04c1f41e13a296493c8eff1bc56 Mon Sep 17 00:00:00 2001 From: Rahul Raj Purohit <46111665+rrajpuro@users.noreply.github.com> Date: Mon, 10 Mar 2025 19:13:08 -0400 Subject: [PATCH 1/2] Update sorted function to sort based on `child.text` value --- hier_config/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hier_config/base.py b/hier_config/base.py index e36a5cf..25735cc 100644 --- a/hier_config/base.py +++ b/hier_config/base.py @@ -109,7 +109,7 @@ def add_deep_copy_of( def all_children_sorted(self) -> Iterator[HConfigChild]: """Recursively find and yield all children sorted at each hierarchy.""" - for child in sorted(self.children): + for child in sorted(self.children, key=lambda child: child.text): yield child yield from child.all_children_sorted() From dc8b297dcca738b8645949d2f2825ed394105893 Mon Sep 17 00:00:00 2001 From: Rahul Raj Purohit <46111665+rrajpuro@users.noreply.github.com> Date: Mon, 10 Mar 2025 19:38:54 -0400 Subject: [PATCH 2/2] Use natural sort instead of lexicographical Better sorting for - ACL numbers - Interface numbers --- hier_config/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hier_config/base.py b/hier_config/base.py index 25735cc..005d687 100644 --- a/hier_config/base.py +++ b/hier_config/base.py @@ -4,6 +4,7 @@ from itertools import chain from logging import getLogger from typing import TYPE_CHECKING, Optional, TypeVar, Union +from natsort import natsorted from .children import HConfigChildren from .exceptions import DuplicateChildError @@ -109,7 +110,7 @@ def add_deep_copy_of( def all_children_sorted(self) -> Iterator[HConfigChild]: """Recursively find and yield all children sorted at each hierarchy.""" - for child in sorted(self.children, key=lambda child: child.text): + for child in natsorted(self.children, key=lambda child: child.text): yield child yield from child.all_children_sorted()