From a4dff044b17f18774c79985db76e0f8526b33431 Mon Sep 17 00:00:00 2001 From: vidit bhargava Date: Wed, 27 Mar 2024 17:29:03 -0400 Subject: [PATCH] Make custom annotation generation deterministic --- stone/backends/python_types.py | 8 ++++++-- stone/cli.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/stone/backends/python_types.py b/stone/backends/python_types.py index 6dc5ea73..19f6fb69 100644 --- a/stone/backends/python_types.py +++ b/stone/backends/python_types.py @@ -701,8 +701,10 @@ def _generate_struct_class_custom_annotations(self, ns, data_type): for field in data_type.fields: field_name = fmt_var(field.name, check_reserved=True) - for annotation_type, processor in self._generate_custom_annotation_processors( - ns, field.data_type, field.custom_annotations): + recursive_processors = list(self._generate_custom_annotation_processors( + ns, field.data_type, field.custom_annotations)) + recursive_processors = sorted(recursive_processors, key=lambda x: x[0].name) + for annotation_type, processor in recursive_processors: annotation_class = class_name_for_annotation_type(annotation_type, ns) self.emit('if annotation_type is {}:'.format(annotation_class)) with self.indent(): @@ -991,6 +993,8 @@ def _generate_union_class_custom_annotations(self, ns, data_type): if len(recursive_processors) == 0: continue + recursive_processors = sorted(recursive_processors, key=lambda x: x[0].name) + field_name = fmt_func(field.name) self.emit('if self.is_{}():'.format(field_name)) diff --git a/stone/cli.py b/stone/cli.py index d02fd18a..232f7b20 100644 --- a/stone/cli.py +++ b/stone/cli.py @@ -2,7 +2,8 @@ A command-line interface for StoneAPI. """ -import importlib +import importlib.util +import importlib.machinery import io import json import logging