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: 70499@debbugs.gnu.org
Cc: "Herman Rimm" <herman@rimm.ee>,
	"Christopher Baines" <guix@cbaines.net>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>,
	"Ricardo Wurmus" <rekado@elephly.net>,
	"Simon Tournier" <zimon.toutoune@gmail.com>,
	"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#70499] [PATCH] utils: Add find-unordered-packages procedure.
Date: Sun, 21 Apr 2024 19:59:49 +0200	[thread overview]
Message-ID: <1f19f015e714d68c84cd91618b1340365c8363bb.1713722288.git.herman@rimm.ee> (raw)

* guix/utils.scm (find-unordered-packages): Add and export procedure.
* tests/utils.scm ("find-unordered-packages"): Add test.

Change-Id: I26ea0fca7d428b192711f75ff3cf5e5a4416b1b6
---
Hello,

I added a procedure which returns the line numbers where packages break
from alphabetical order, e.g.:

  scheme@(guix-user)> (lset-xor eqv? (find-unordered-packages
  "gnu/packages/crates-io.scm"))
  $1 = (626 1153 2693 2715 2840 4074 4139 4187 6099 6243 6382 6896 7677
  9465 10346 11424 12089 12552 12676 12887 16147 16364 16897 18195 18260
  19912 21335 22489 22792 23898 24344 24801 25443 25492 26591 27832
  27944 31206 32365 32502 32609 32770 34281 34913 36192 36320 36621
  36718 36828 37511 38169 39000 39360 39684 40921 41153 41459 41501
  42121 42803 42910 44318 44585 46435 47350 47456 47709 48043 49624
  49905 51084 51216 51560 53586 54473 57062 58925 59048 59134 59584
  59664 59702 59914 62399 66006 66266 66391 68003 68200 68244 70292
  70321 71660 71686 71761 72643 73746 73880 74434 74459 77309 77646
  78136 79569 81722 81896 83802 85617 87167 89037 92212)

It could be extended to also expect package versions in decreasing
order. Maybe I can use it to sort packages automatically later. 

Cheers,
Herman
 guix/utils.scm  | 21 +++++++++++++++++++++
 tests/utils.scm | 19 +++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/guix/utils.scm b/guix/utils.scm
index d8ce6ed886..f690618306 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -148,6 +148,7 @@ (define-module (guix utils)
             delete-expression
             insert-expression
             find-definition-insertion-location
+            find-unordered-packages
 
             filtered-port
             decompressed-port
@@ -531,6 +532,26 @@ (define (find-definition-insertion-location file term)
            (and (not (eof-object? syntax))
                 (syntax-source syntax))))))))
 
+(define (find-unordered-packages file)
+  "Return the line numbers of top-level package definitions whose name
+alphabetically preceeds the previous name."
+  (call-with-input-file file
+    (lambda (port)
+      (let loop ((lst '())
+                 (previous-name ""))
+        (match (read-syntax port)
+          ((? eof-object?)
+           (reverse! lst))
+          (exp
+            (match (syntax->datum exp)
+              (('define-public _ (or ('package _ ('name name) _ ...)
+                                     ('package ('name name) _ ...)))
+               (loop (if (string< name previous-name)
+                         (cons (assoc-ref (syntax-source exp) 'line) lst)
+                         lst)
+                     name))
+              (_ (loop lst previous-name)))))))))
+
 \f
 ;;;
 ;;; Keyword arguments.
diff --git a/tests/utils.scm b/tests/utils.scm
index 462e43e2b1..8956ea5420 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -303,6 +303,25 @@ (define-public package-2\n  'package)\n"
            (find-definition-insertion-location temp-file term))
          (list 'package 'package-1 'package-2))))
 
+(test-equal "find-unordered-packages"
+  (list 7)
+  (begin
+    (call-with-output-file temp-file
+      (lambda (port)
+        (display "
+(define-public rust-addr2line-0.19
+  (package
+    (inherit rust-addr2line-0.21)
+    (name \"rust-addr2line\")
+    (version \"0.19.0\")))
+
+(define-public rust-addchain-0.2
+  (package
+    (name \"rust-addchain\")
+    (version \"0.2.0\")))
+" port)))
+    (find-unordered-packages temp-file)))
+
 (test-equal "string-distance"
   '(0 1 1 5 5)
   (list

base-commit: a1d711c92e119f6b5b8e99a620cdba92a4ca3bfb
-- 
2.41.0





             reply	other threads:[~2024-04-21 18:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-21 17:59 Herman Rimm via Guix-patches via [this message]
2024-05-01 10:30 ` [bug#70499] [PATCH] utils: Add find-unordered-packages procedure Ludovic Courtès
2024-05-05 17:25 ` [bug#70499] [PATCH v2 0/3] Lint package order Herman Rimm via Guix-patches via
2024-05-05 17:25   ` [bug#70499] [PATCH v2 1/3] guix: Move ‘package-location<?’ to (guix packages) Herman Rimm via Guix-patches via
2024-05-05 17:25   ` [bug#70499] [PATCH v2 2/3] ui: Make 'user-module' parameter of 'load*' optional Herman Rimm via Guix-patches via
2024-05-05 17:25   ` [bug#70499] [PATCH v2 3/3] scripts: lint: Add 'whole-file' option with ordering lint 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=1f19f015e714d68c84cd91618b1340365c8363bb.1713722288.git.herman@rimm.ee \
    --to=guix-patches@gnu.org \
    --cc=70499@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=rekado@elephly.net \
    --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.