Skip to content

Commit

Permalink
Merge pull request #425 from GaetanLepage/sort-systems
Browse files Browse the repository at this point in the history
Sort systems in stdout
  • Loading branch information
Mic92 authored Oct 9, 2024
2 parents b5e33d2 + bbc18ee commit e363f5b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nixpkgs_review/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Literal

from .nix import Attr
from .utils import System, info, link, skipped, warn
from .utils import System, info, link, skipped, system_order_key, warn


def print_number(
Expand Down Expand Up @@ -141,7 +141,7 @@ def order_reports(reports: dict[System, SystemReport]) -> dict[System, SystemRep
return dict(
sorted(
reports.items(),
key=lambda item: "".join(reversed(item[0].split("-"))),
key=lambda item: system_order_key(system=item[0]),
reverse=True,
)
)
Expand Down
12 changes: 9 additions & 3 deletions nixpkgs_review/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .github import GithubClient
from .nix import Attr, nix_build, nix_eval, nix_shell
from .report import Report
from .utils import System, current_system, info, sh, warn
from .utils import System, current_system, info, sh, system_order_key, warn

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

changed_attrs = {}
for system in self.systems:
# Systems ordered correctly (x86_64-linux, aarch64-linux, x86_64-darwin, aarch64-darwin)
sorted_systems: list[System] = sorted(
list(self.systems),
key=system_order_key,
reverse=True,
)
changed_attrs: dict[System, set[str]] = {}
for system in sorted_systems:
changed_pkgs, removed_pkgs = differences(
base_packages[system], merged_packages[system]
)
Expand Down
17 changes: 17 additions & 0 deletions nixpkgs_review/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,20 @@ def nix_nom_tool() -> str:
return "nom"

return "nix"


def system_order_key(system: System) -> str:
"""
For a consistent UI, we keep the platforms sorted as such:
- x86_64-linux
- aarch64-linux
- x86_64-darwin
- aarch64-darwin
This helper turns a system name to an alias which can then be sorted in the anti-alphabetical order.
(i.e. should be used in `sort` with `reverse=True`)
Example:
`aarch64-linux` -> `linuxaarch64`
"""
return "".join(reversed(system.split("-")))

0 comments on commit e363f5b

Please sign in to comment.