From patchwork Sun Apr 21 17:59:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herman Rimm X-Patchwork-Id: 63282 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D703E27BBEA; Sun, 21 Apr 2024 19:01:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id EB6C127BBE2 for ; Sun, 21 Apr 2024 19:01:19 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rybUx-0000L9-K0; Sun, 21 Apr 2024 14:01:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rybUw-0000Kr-A8 for guix-patches@gnu.org; Sun, 21 Apr 2024 14:01:06 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rybUv-00059x-AQ; Sun, 21 Apr 2024 14:01:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rybV5-0003V4-HF; Sun, 21 Apr 2024 14:01:15 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70499] [PATCH] utils: Add find-unordered-packages procedure. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 21 Apr 2024 18:01:12 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 70499 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70499@debbugs.gnu.org Cc: Herman Rimm , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.171372244813267 (code B ref -1); Sun, 21 Apr 2024 18:01:12 +0000 Received: (at submit) by debbugs.gnu.org; 21 Apr 2024 18:00:48 +0000 Received: from localhost ([127.0.0.1]:44092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rybUU-0003QU-Aa for submit@debbugs.gnu.org; Sun, 21 Apr 2024 14:00:46 -0400 Received: from lists.gnu.org ([2001:470:142::17]:33940) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rybUK-0003Ok-Ss for submit@debbugs.gnu.org; Sun, 21 Apr 2024 14:00:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rybTz-00006Z-T1 for guix-patches@gnu.org; Sun, 21 Apr 2024 14:00:07 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117] helo=email.rimm.ee) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1rybTx-0004kE-Ia for guix-patches@gnu.org; Sun, 21 Apr 2024 14:00:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1713722399; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=P4Hc2P0rNwb3axplX6ma8y5czDIXuQiiAas7NzZ4X6Q=; b=JztqxP5fGU3KeWXJyFeEErLkWayvhmtkFL2r++s3Y1mFveJxt1QZsM0yUzEuL4CniXkrcJ RXMkaaESUGewPkDaGsFPhID/JlFMHjHlc3YnVm8/akatHnmLafknMgo+63sk6YuAi8sobI awKTE0aeFgsoJD19QAsB0mXOeF2MqWIgyzrV9qSFvW0Gix6sULod5LLOU5+VbVhF+3T8z1 QHMKZo42IOoa7JXd4sevFa0D44UU1D0BDlE61FWJ48TvtalB6Momecl1+BiOAp8I7KuQAL XfTI5MZ/Kwixwh9gIadplY6fSppYlWr2QmgFxyicPeXy+dovjrskQKpiZRrWUg== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 058b0cdc (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Sun, 21 Apr 2024 17:59:58 +0000 (UTC) Date: Sun, 21 Apr 2024 19:59:49 +0200 Message-ID: <1f19f015e714d68c84cd91618b1340365c8363bb.1713722288.git.herman@rimm.ee> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=81.205.150.117; envelope-from=herman@rimm.ee; helo=email.rimm.ee X-Spam_score_int: 16 X-Spam_score: 1.6 X-Spam_bar: + X-Spam_report: (1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_PBL=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_RCVD_IP=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches X-Patchwork-Original-From: Herman Rimm via Guix-patches via From: Herman Rimm Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * 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(+) base-commit: a1d711c92e119f6b5b8e99a620cdba92a4ca3bfb 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))))))))) + ;;; ;;; 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