From a9fa2af6a24dbbe6e7071be7c7faf0c89c3c1089 Mon Sep 17 00:00:00 2001 From: Gerard Casas Saez Date: Tue, 11 Jul 2023 18:30:26 +0200 Subject: [PATCH 1/4] Ensure imports are sorted --- protogen/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protogen/__init__.py b/protogen/__init__.py index ed227af..f4afbd7 100644 --- a/protogen/__init__.py +++ b/protogen/__init__.py @@ -1560,9 +1560,10 @@ def print_import(self): def _proto(self) -> google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.File: if self._import_mark > -1: + sorted_imports = sort(self._imports, key=lambda x:x._path, reverse=True) lines = ( self._buf[: self._import_mark] - + [f"import {p._path}" for p in self._imports] + + [f"import {p._path}" for p in sorted_imports] + self._buf[self._import_mark :] ) else: From 1398a8884c096cfda411c1553b4f6655e85d2f0b Mon Sep 17 00:00:00 2001 From: Gerard Casas Saez Date: Tue, 11 Jul 2023 18:54:18 +0200 Subject: [PATCH 2/4] s/sort/sorted --- protogen/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protogen/__init__.py b/protogen/__init__.py index f4afbd7..1f0c103 100644 --- a/protogen/__init__.py +++ b/protogen/__init__.py @@ -1560,7 +1560,7 @@ def print_import(self): def _proto(self) -> google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.File: if self._import_mark > -1: - sorted_imports = sort(self._imports, key=lambda x:x._path, reverse=True) + sorted_imports = sorted(self._imports, key=lambda x:x._path, reverse=True) lines = ( self._buf[: self._import_mark] + [f"import {p._path}" for p in sorted_imports] From afc4c3206ccf442629e1d5726ef900a8127e23d1 Mon Sep 17 00:00:00 2001 From: Gerard Casas Saez Date: Tue, 11 Jul 2023 19:00:09 +0200 Subject: [PATCH 3/4] avoid reverse=True --- protogen/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protogen/__init__.py b/protogen/__init__.py index 1f0c103..68e179b 100644 --- a/protogen/__init__.py +++ b/protogen/__init__.py @@ -1560,7 +1560,7 @@ def print_import(self): def _proto(self) -> google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.File: if self._import_mark > -1: - sorted_imports = sorted(self._imports, key=lambda x:x._path, reverse=True) + sorted_imports = sorted(self._imports, key=lambda x:x._path) lines = ( self._buf[: self._import_mark] + [f"import {p._path}" for p in sorted_imports] From b8a4e13502252c9bb3220e7d260be9a34f558acf Mon Sep 17 00:00:00 2001 From: Gerard Casas Saez Date: Fri, 14 Jul 2023 19:19:28 +0200 Subject: [PATCH 4/4] fix black formatting --- protogen/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protogen/__init__.py b/protogen/__init__.py index 68e179b..bd253bc 100644 --- a/protogen/__init__.py +++ b/protogen/__init__.py @@ -1560,7 +1560,7 @@ def print_import(self): def _proto(self) -> google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.File: if self._import_mark > -1: - sorted_imports = sorted(self._imports, key=lambda x:x._path) + sorted_imports = sorted(self._imports, key=lambda x: x._path) lines = ( self._buf[: self._import_mark] + [f"import {p._path}" for p in sorted_imports]