Skip to content

Commit

Permalink
Change a few list sorting orders in generated code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcvmoole committed Nov 1, 2024
1 parent 6e06bf6 commit 75ba04c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pysmi/codegen/templates/pysnmp/mib-definitions.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}
Expand Down

0 comments on commit 75ba04c

Please sign in to comment.