From 75ba04c11ebe168b9f55eac09e82a58d3e486c65 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Tue, 22 Oct 2024 15:48:52 +0000 Subject: [PATCH] Change a few list sorting orders in generated code This commit combines two changes that have only a non-functional impact on generated Python code: o The enumeration lists (namedValues) are sorted by numeric value rather than by name. The new sorting order is more in line with what is found in most MIBs, usually easier to read, and more consistent with the sorting order before the introduction of Jinja2 templates. o The static list of imported constraint classes is rearranged to be alphabetic. The previous order made little sense. Seeing as neither aspect should be relied upon, no tests are added here. --- pysmi/codegen/templates/pysnmp/mib-definitions.j2 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pysmi/codegen/templates/pysnmp/mib-definitions.j2 b/pysmi/codegen/templates/pysnmp/mib-definitions.j2 index 2b8eb23..626eba2 100644 --- a/pysmi/codegen/templates/pysnmp/mib-definitions.j2 +++ b/pysmi/codegen/templates/pysnmp/mib-definitions.j2 @@ -22,16 +22,16 @@ Managed Objects Instances. {% block asn1_constraints_imports scoped %} (ConstraintsIntersection, + ConstraintsUnion, SingleValueConstraint, ValueRangeConstraint, - ValueSizeConstraint, - ConstraintsUnion) = mibBuilder.importSymbols( + ValueSizeConstraint) = mibBuilder.importSymbols( "ASN1-REFINEMENT", "ConstraintsIntersection", + "ConstraintsUnion", "SingleValueConstraint", "ValueRangeConstraint", - "ValueSizeConstraint", - "ConstraintsUnion") + "ValueSizeConstraint") {% endblock -%} {% block smi_imports scoped %} @@ -127,7 +127,7 @@ if mibBuilder.loadTexts: ) ) namedValues = NamedValues( - {% for name, iden in spec['enumeration'].items()|sort %} + {% for name, iden in spec['enumeration'].items()|sort(attribute='1') %} {% if loop.first and loop.last %} ("{{ name}}", {{ iden }}) {% elif loop.first %} @@ -156,7 +156,7 @@ if mibBuilder.loadTexts: {% macro bits(namedbits) %} namedValues = NamedValues( - {% for name, iden in namedbits.items()|sort %} + {% for name, iden in namedbits.items()|sort(attribute='1') %} {% if loop.first and loop.last %} ("{{ name}}", {{ iden }}) {% elif loop.first %}