unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#70499] [PATCH] utils: Add find-unordered-packages procedure.
@ 2024-04-21 17:59 Herman Rimm via Guix-patches via
  2024-05-01 10:30 ` Ludovic Courtès
  2024-05-05 17:25 ` [bug#70499] [PATCH v2 0/3] Lint package order Herman Rimm via Guix-patches via
  0 siblings, 2 replies; 8+ messages in thread
From: Herman Rimm via Guix-patches via @ 2024-04-21 17:59 UTC (permalink / raw)
  To: 70499
  Cc: Herman Rimm, Christopher Baines, Josselin Poiret,
	Ludovic Courtès, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

* 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





^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-07-04 20:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-21 17:59 [bug#70499] [PATCH] utils: Add find-unordered-packages procedure Herman Rimm via Guix-patches via
2024-05-01 10:30 ` 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
2024-05-25 14:06   ` [bug#70499] [PATCH v2 0/3] Lint package order Ludovic Courtès
2024-07-04 20:26     ` Herman Rimm via Guix-patches via

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).