all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Herman Rimm via Guix-patches via <guix-patches@gnu.org>
To: 74979@debbugs.gnu.org
Cc: "Christopher Baines" <guix@cbaines.net>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>,
	"Simon Tournier" <zimon.toutoune@gmail.com>,
	"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#74979] [PATCH 1/4] scripts: style: Refactor order-packages.
Date: Thu, 19 Dec 2024 20:33:04 +0100	[thread overview]
Message-ID: <bccdc8fe4884bf1f114a1f07eac3a3a3b25081e0.1734636205.git.herman@rimm.ee> (raw)
In-Reply-To: <cover.1734636205.git.herman@rimm.ee>

* guix/scripts/style.scm (order-packages): Combine package-name and
package-version procedures into package-fields.
(format-whole-file): Do not sort copyright headers or module definition.

Change-Id: I5507bf8ed221f7017f972f0e0e64d149bea4854b
---
 guix/scripts/style.scm | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm
index 51234952e9..4b704ddfb7 100644
--- a/guix/scripts/style.scm
+++ b/guix/scripts/style.scm
@@ -43,6 +43,7 @@ (define-module (guix scripts style)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
+  #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-37)
@@ -500,31 +501,19 @@ (define (order-packages lst)
   "Return LST, a list of top-level expressions and blanks, with
 top-level package definitions in alphabetical order.  Packages which
 share a name are placed with versions in descending order."
-  (define (package-name pkg)
+  (define (package-fields pkg)
     (match pkg
       ((('define-public _ expr) _ ...)
        (match expr
-         ((or ('package _ ('name name) _ ...)
-              ('package ('name name) _ ...))
-          name)
-         (_ #f)))
-      (_ #f)))
-
-  (define (package-version pkg)
-    (match pkg
-      ((('define-public _ expr) _ ...)
-       (match expr
-         ((or ('package _ _ ('version version) _ ...)
-              ('package _ ('version version) _ ...))
-          version)
-         (_ #f)))
-      (_ #f)))
+         ((or ('package _ ('name name) ('version version) _ ...)
+              ('package ('name name) ('version version) _ ...))
+          (values name version))
+         (_ (values #f #f))))
+      (_ (values #f #f))))
 
   (define (package>? lst1 lst2)
-    (let ((name1 (package-name lst1))
-          (name2 (package-name lst2))
-          (version1 (package-version lst1))
-          (version2 (package-version lst2)))
+    (let-values (((name1 version1) (package-fields lst1))
+                 ((name2 version2) (package-fields lst2)))
       (and name1 name2 (or (string>? name1 name2)
                            (and (string=? name1 name2)
                                 version1
@@ -550,7 +539,12 @@ (define* (format-whole-file file order? #:rest rest)
     (let* ((lst (call-with-input-file file read-with-comments/sequence
                                       #:guess-encoding #t))
            (lst (if order?
-                    (order-packages lst)
+                    (let loop ((lst lst))
+                      (match lst
+                        (((? blank? blank) rest ...)
+                         (cons blank (loop rest)))
+                        ((module rest ...)
+                         (cons module (order-packages rest)))))
                     lst)))
       (with-atomic-file-output file
         (lambda (port)
-- 
2.45.2





  reply	other threads:[~2024-12-19 19:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-19 19:31 [bug#74979] [PATCH 0/4] scripts: style: Sort more kinds of package Herman Rimm via Guix-patches via
2024-12-19 19:33 ` Herman Rimm via Guix-patches via [this message]
2024-12-19 19:33 ` [bug#74979] [PATCH 2/4] scripts: style: Sort more kinds of package definitions Herman Rimm via Guix-patches via
2024-12-19 19:33 ` [bug#74979] [PATCH 3/4] scripts: style: Only sort packages with string literal name Herman Rimm via Guix-patches via
2024-12-19 19:33 ` [bug#74979] [PATCH 4/4] scripts: style: Warn about unmatched package definitions Herman Rimm via Guix-patches via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bccdc8fe4884bf1f114a1f07eac3a3a3b25081e0.1734636205.git.herman@rimm.ee \
    --to=guix-patches@gnu.org \
    --cc=74979@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=guix@cbaines.net \
    --cc=herman@rimm.ee \
    --cc=ludo@gnu.org \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.