From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id YABuCZ98xmXnDAEAe85BDQ:P1 (envelope-from ) for ; Fri, 09 Feb 2024 20:27:27 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id YABuCZ98xmXnDAEAe85BDQ (envelope-from ) for ; Fri, 09 Feb 2024 20:27:27 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=Uhr+SwCw; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1707506847; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=qxhQEJqZIKomoOppxc2+l6rUODdzvnDtMhWKcvtj1CA=; b=cVdUs78Xp2Yz1abzy8kq3j3utMp92qgj++NzKQsbmmd5HALafZSeoHS2IFZfpqaE+fVrf3 nangTUBHpRXS/8NDwH765rfph0frTVeEZe+OONri9jy9WXppi3y1nleT42+WUoDQCmYV1+ Nc6fXvigEoblfgBX2Fr1NOb73agfN3fQ09mIhol1HLDB8VqjEhmclkZgk+B2EWVgiHbiCf X/oMujVTBH3TXpKx2oF1aWZYAZwnSB3m9mbJnomj4tX7Miv8IJ7lmrr04gXK5/MoZMMVkb vERep9TaR1/lejiN0KbfjOPSTeehcSMI70UJbLLG+CWYGNQblx0mybQxGTn7gQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=Uhr+SwCw; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1707506847; a=rsa-sha256; cv=none; b=TSRRJlKROV0P3jPt1RR6ELHNz7xeVU1IKldoi8ml7iCoJc1LbKe2A65S3eg4LwITE4wber jiohLL4yWeyg02AbnNwCgqrTYQqq8GD1HWY4Iu9HgfLquqZiJ7Xd8Vtwe5em4M+ZR33HKK GAtlzFI+qA2omX15QU3pDnfGiJglgxNozBBGnqbp/uc5XlacrSbOBcnhEnecnJiJuq+tIV znLPOW6gGuytPgMx+XQOZKfxONGbf/zdhjmk4nL1FJsnhsZ+X/OOnDNvoqI2e85t8rTapL 7EkNMbcF3fLdAhuCjfiPoSi0aEM06VkjtlmHrvhSoEcs1lXwT4p42C1UrCXf5w== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6E7E03F832 for ; Fri, 9 Feb 2024 20:27:26 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYWWS-0002VM-IC; Fri, 09 Feb 2024 14:26:52 -0500 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 1rYWWR-0002Uk-Fw for guix-patches@gnu.org; Fri, 09 Feb 2024 14:26:51 -0500 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 1rYWWR-0000ht-7C; Fri, 09 Feb 2024 14:26:51 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rYWWd-0001bZ-W2; Fri, 09 Feb 2024 14:27:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68935] [PATCH v2 5/6] import: Insert packages into modules alphabetically. 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: Fri, 09 Feb 2024 19:27:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68935 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68935@debbugs.gnu.org Cc: ludo@gnu.org, 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-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 68935-submit@debbugs.gnu.org id=B68935.17075068086084 (code B ref 68935); Fri, 09 Feb 2024 19:27:03 +0000 Received: (at 68935) by debbugs.gnu.org; 9 Feb 2024 19:26:48 +0000 Received: from localhost ([127.0.0.1]:60236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rYWWN-0001a0-RJ for submit@debbugs.gnu.org; Fri, 09 Feb 2024 14:26:48 -0500 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:51759 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rYWWK-0001YI-Bs for 68935@debbugs.gnu.org; Fri, 09 Feb 2024 14:26:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1707506774; 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: in-reply-to:in-reply-to:references:references; bh=qxhQEJqZIKomoOppxc2+l6rUODdzvnDtMhWKcvtj1CA=; b=Uhr+SwCwYPEuZWSKDFVsSA8G8ivh/7omDOrh9GGNKsbBgZSyIg1CwQaPNyhW2ae/05oLoV 5+c6hq4LNeeHWaITCL0uApLZnYza/9qmQClRqrtvJLNGqf3WGUPEFwoGY/kCkwLZ/cB4LO MTFcGT0cjFdUDKzUzatq9dFUjWzAJtFiaTZoYNBukdmPHIAbbny+2YQNhFx/qyrcRrkUvt x1axrtJ0qnzUuhDY7455nujlngHRDI+4jiNNszZOApuJnFvv2kFIdLj0S/aU7hTKsZtz6m Zo+HwIMsR6ee+L6k9G34DiOFdp+qUH+p9FopWOrfRLeWxXYxHnqo2qkLJlR2uQ== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id e19af69d (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Fri, 9 Feb 2024 19:26:14 +0000 (UTC) Date: Fri, 9 Feb 2024 20:25:17 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <3c0da641938e96a9f0c491abb74b30c75634df9a.1707505804.git.herman@rimm.ee> References: <3c0da641938e96a9f0c491abb74b30c75634df9a.1707505804.git.herman@rimm.ee> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Herman Rimm via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -5.17 X-Migadu-Queue-Id: 6E7E03F832 X-Spam-Score: -5.17 X-Migadu-Scanner: mx11.migadu.com X-TUID: wPU/m5ssoxM6 * guix/scripts/import.scm (guix-import): Add 'insert' option. (define-import): Add procedure. * doc/guix.texi (Invoking guix import): Describe 'insert' option. Change-Id: Id021095355283ade79acde120890eb2ce9173cf7 --- doc/guix.texi | 14 ++++++-- guix/scripts/import.scm | 80 ++++++++++++++++++++++++++--------------- 2 files changed, 63 insertions(+), 31 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 2908085c36..c73db5cbbf 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -124,6 +124,7 @@ Copyright @copyright{} 2023 Saku Laesvuori@* Copyright @copyright{} 2023 Graham James Addis@* Copyright @copyright{} 2023 Tomas Volf@* +Copyright @copyright{} 2024 Herman Rimm@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -14178,12 +14179,21 @@ Invoking guix import The general syntax is: @example -guix import @var{importer} @var{options}@dots{} +guix import [@var{global-options}@dots{}] @var{importer} @var{package} [@var{options}@dots{}] @end example @var{importer} specifies the source from which to import package metadata, and @var{options} specifies a package identifier and other -options specific to @var{importer}. +options specific to @var{importer}. @command{guix import} itself has the +following @var{global-options}: + +@table @code +@item --insert=@var{file} +@itemx -i @var{file} +Insert the package definition(s) that the @var{importer} generated into the +specified @var{file}, either in alphabetical order among existing package +definitions, or at the end of the file otherwise. +@end table Some of the importers rely on the ability to run the @command{gpgv} command. For these, GnuPG must be installed and in @code{$PATH}; run @code{guix install diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm index 77fcfe3990..850887e720 100644 --- a/guix/scripts/import.scm +++ b/guix/scripts/import.scm @@ -67,10 +67,39 @@ (define (show-help) (display (G_ " -h, --help display this help and exit")) (display (G_ " + -i, --insert insert into package module alphabetically")) + (display (G_ " -V, --version display version information and exit")) (newline) (show-bug-report-information)) +(define (define-import importer args proc) + "Wrap package expressions from IMPORTER with 'define-public and invoke +PROC callback." + (if (member importer importers) + (match (apply (resolve-importer importer) args) + ((and expr (or ('package _ ...) + ('let _ ...))) + (proc (package->definition expr))) + ((and expr ('define-public _ ...)) + (proc expr)) + ((? list? expressions) + (for-each (lambda (expr) + (match expr + ((and expr (or ('package _ ...) + ('let _ ...))) + (proc (package->definition expr))) + ((and expr ('define-public _ ...)) + (proc expr)))) + expressions)) + (x + (leave (G_ "'~a' import failed~%") importer))) + (let ((hint (string-closest importer importers #:threshold 3))) + (report-error (G_ "~a: invalid importer~%") importer) + (when hint + (display-hint (G_ "Did you mean @code{~a}?~%") hint)) + (exit 1)))) + (define-command (guix-import . args) (category packaging) (synopsis "import a package definition from an external repository") @@ -84,33 +113,26 @@ (define-command (guix-import . args) (exit 0)) ((or ("-V") ("--version")) (show-version-and-exit "guix import")) + ((or ("-i" module importer args ...) + ("--insert" module importer args ...)) + (let ((find-and-insert + (lambda (expr) + (let ((insert + (lambda (source-properties) + (if source-properties + (insert-expression source-properties expr) + (let ((port (open-file file "a"))) + (pretty-print-with-comments port expr) + (newline port) + (close-port port)))))) + (find-expression module expr insert))))) + (define-import importer args find-and-insert))) ((importer args ...) - (if (member importer importers) - (let ((print (lambda (expr) - (leave-on-EPIPE - (pretty-print-with-comments (current-output-port) expr))))) - (match (apply (resolve-importer importer) args) - ((and expr (or ('package _ ...) - ('let _ ...))) - (print (package->definition expr))) - ((and expr ('define-public _ ...)) - (print expr)) - ((? list? expressions) - (for-each (lambda (expr) - (match expr - ((and expr (or ('package _ ...) - ('let _ ...))) - (print (package->definition expr))) - ((and expr ('define-public _ ...)) - (print expr))) - ;; Two newlines: one after the closing paren, and - ;; one to leave a blank line. - (newline) (newline)) - expressions)) - (x - (leave (G_ "'~a' import failed~%") importer)))) - (let ((hint (string-closest importer importers #:threshold 3))) - (report-error (G_ "~a: invalid importer~%") importer) - (when hint - (display-hint (G_ "Did you mean @code{~a}?~%") hint)) - (exit 1)))))) + (let ((print (lambda (expr) + (leave-on-EPIPE + (pretty-print-with-comments + (current-output-port) expr) + ;; Two newlines: one after the closing paren, and + ;; one to leave a blank line. + (newline) (newline))))) + (define-import importer args print))))) -- 2.41.0