From 6ad2e407ebb6bf87bc30cc30d1b6f9d688a17854 Mon Sep 17 00:00:00 2001 From: Herman Rimm Date: Tue, 21 Jan 2025 22:43:01 +0100 Subject: [PATCH] scripts: style: Sort more kinds of package definitions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/scripts/style.scm (order-packages): Match comments before package S-exp. and its fields. Match in let. Match package/inherit. * tests/guix-style.sh: Add pkg-baz variable and package/inherit to test. Change-Id: I48a5976930501c20415b5413966b5294958bc23b Signed-off-by: Ludovic Courtès --- guix/scripts/style.scm | 13 +++++++------ tests/guix-style.sh | 10 ++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm index 4b704ddfb7e..6f07f6c3b9e 100644 --- a/guix/scripts/style.scm +++ b/guix/scripts/style.scm @@ -503,13 +503,14 @@ top-level package definitions in alphabetical order. Packages which share a name are placed with versions in descending order." (define (package-fields pkg) (match pkg - ((('define-public _ expr) _ ...) + ((('define-public pkg _ ... (or ('let _ expr) expr)) _ ...) (match expr - ((or ('package _ ('name name) ('version version) _ ...) - ('package ('name name) ('version version) _ ...)) - (values name version)) - (_ (values #f #f)))) - (_ (values #f #f)))) + (((or 'package 'package/inherit) fields ...) + (let ((name (and=> (assoc-ref fields 'name) first)) + (version (and=> (assoc-ref fields 'version) first))) + (values name version))) + (_ (and (values #f #f))))) + (_ (and (values #f #f))))) (define (package>? lst1 lst2) (let-values (((name1 version1) (package-fields lst1)) diff --git a/tests/guix-style.sh b/tests/guix-style.sh index 93331394353..703e148b699 100644 --- a/tests/guix-style.sh +++ b/tests/guix-style.sh @@ -65,10 +65,16 @@ cat > "$tmpfile" <