22
33from datetime import datetime
44from inspect import cleandoc
5- from itertools import chain
65from pathlib import Path
76
87from exasol .toolbox .util .dependencies .poetry_dependencies import (
@@ -75,16 +74,12 @@ def _describe_dependency_changes(self) -> str:
7574 )
7675
7776 changes_by_group : list [str ] = []
78- # preserve order of keys from old group
79- groups = list (
80- dict .fromkeys (
81- chain (
82- previous_dependencies_in_groups .keys (),
83- current_dependencies_in_groups .keys (),
84- )
85- )
77+ # dict.keys() returns a set
78+ all_groups = (
79+ previous_dependencies_in_groups .keys ()
80+ | current_dependencies_in_groups .keys ()
8681 )
87- for group in groups :
82+ for group in self . _sort_groups ( all_groups ) :
8883 previous_dependencies = previous_dependencies_in_groups .get (group , {})
8984 current_dependencies = current_dependencies_in_groups .get (group , {})
9085 changes = DependencyChanges (
@@ -96,6 +91,21 @@ def _describe_dependency_changes(self) -> str:
9691 changes_by_group .append (f"\n ### `{ group } `\n { changes_str } \n " )
9792 return "" .join (changes_by_group )
9893
94+ @staticmethod
95+ def _sort_groups (groups : set [str ]) -> list [str ]:
96+ """
97+ Prepare a deterministic sorting for groups shown in the versioned changes file:
98+ - `main` group should always be first
99+ - remaining groups are sorted alphabetically
100+ """
101+ main = "main"
102+ if main not in groups :
103+ # sorted converts set to list
104+ return sorted (groups )
105+ remaining_groups = groups - {main }
106+ # sorted converts set to list
107+ return [main ] + sorted (remaining_groups )
108+
99109 def _update_changelog_table_of_contents (self ) -> None :
100110 """
101111 Read in existing `changelog.md` and append to appropriate sections
0 commit comments