Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort systems in stdout #425

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("-")))