Skip to content

Commit e363f5b

Browse files
authored
Merge pull request #425 from GaetanLepage/sort-systems
Sort systems in stdout
2 parents b5e33d2 + bbc18ee commit e363f5b

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

nixpkgs_review/report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Literal
77

88
from .nix import Attr
9-
from .utils import System, info, link, skipped, warn
9+
from .utils import System, info, link, skipped, system_order_key, warn
1010

1111

1212
def print_number(
@@ -141,7 +141,7 @@ def order_reports(reports: dict[System, SystemReport]) -> dict[System, SystemRep
141141
return dict(
142142
sorted(
143143
reports.items(),
144-
key=lambda item: "".join(reversed(item[0].split("-"))),
144+
key=lambda item: system_order_key(system=item[0]),
145145
reverse=True,
146146
)
147147
)

nixpkgs_review/review.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .github import GithubClient
1717
from .nix import Attr, nix_build, nix_eval, nix_shell
1818
from .report import Report
19-
from .utils import System, current_system, info, sh, warn
19+
from .utils import System, current_system, info, sh, system_order_key, warn
2020

2121
# keep up to date with `supportedPlatforms`
2222
# https://github.com/NixOS/ofborg/blob/cf2c6712bd7342406e799110e7cd465aa250cdca/ofborg/src/outpaths.nix#L12
@@ -212,8 +212,14 @@ def build_commit(
212212
for system in self.systems
213213
}
214214

215-
changed_attrs = {}
216-
for system in self.systems:
215+
# Systems ordered correctly (x86_64-linux, aarch64-linux, x86_64-darwin, aarch64-darwin)
216+
sorted_systems: list[System] = sorted(
217+
list(self.systems),
218+
key=system_order_key,
219+
reverse=True,
220+
)
221+
changed_attrs: dict[System, set[str]] = {}
222+
for system in sorted_systems:
217223
changed_pkgs, removed_pkgs = differences(
218224
base_packages[system], merged_packages[system]
219225
)

nixpkgs_review/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,20 @@ def nix_nom_tool() -> str:
7676
return "nom"
7777

7878
return "nix"
79+
80+
81+
def system_order_key(system: System) -> str:
82+
"""
83+
For a consistent UI, we keep the platforms sorted as such:
84+
- x86_64-linux
85+
- aarch64-linux
86+
- x86_64-darwin
87+
- aarch64-darwin
88+
89+
This helper turns a system name to an alias which can then be sorted in the anti-alphabetical order.
90+
(i.e. should be used in `sort` with `reverse=True`)
91+
92+
Example:
93+
`aarch64-linux` -> `linuxaarch64`
94+
"""
95+
return "".join(reversed(system.split("-")))

0 commit comments

Comments
 (0)