From unknown Sun Jun 22 07:40:19 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#78277] [PATCH] ui: Allow evaluating multi-expressions strings with read/eval. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 06 May 2025 07:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 78277 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 78277@debbugs.gnu.org Cc: Maxim Cournoyer , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , 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 , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.174651737830955 (code B ref -1); Tue, 06 May 2025 07:43:02 +0000 Received: (at submit) by debbugs.gnu.org; 6 May 2025 07:42:58 +0000 Received: from localhost ([127.0.0.1]:49317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uCCx7-00083C-SX for submit@debbugs.gnu.org; Tue, 06 May 2025 03:42:58 -0400 Received: from lists.gnu.org ([2001:470:142::17]:38814) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uCCx2-00081w-3B for submit@debbugs.gnu.org; Tue, 06 May 2025 03:42:53 -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 1uCCwl-0000LO-U1 for guix-patches@gnu.org; Tue, 06 May 2025 03:42:37 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uCCwk-0007Gm-5Z for guix-patches@gnu.org; Tue, 06 May 2025 03:42:35 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-b0b2d0b2843so4064840a12.2 for ; Tue, 06 May 2025 00:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746517352; x=1747122152; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nlCGfZZ8LgtWfXxSebXYnGZrqkK4+W1/l+V4S+sEa/M=; b=dGcop3HF4yTGioPrXvregoxt65C2PN16OJHUwAETyzkQJQZvF2dxm7RTgUfaaiRDcJ ck6VVywjKXSdxHRIDroIx5pQlsYsk8VPngG07RKfbiXASb3Si8rkeDLxF9B1PXsNzHWR 4Tr0/cGqhWu7qby1QhIiKCIUstEmEM9CnGH+XxwisDpOZ0EIWo6Qf9Somb1vYUScqobm Lgf5tgNdlyVRIvHxyjxpGpCUtnd7BcK7Zfr6jEXvNdNv9us+9kQwiEhHPhKv5LsPGDmh Y0qx3AACkit0u9lvf+6CMVK3Fp6oImAx7gsmsK6z3PjnezHPa2xAt7ozDgioXrJag9az JzZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746517352; x=1747122152; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nlCGfZZ8LgtWfXxSebXYnGZrqkK4+W1/l+V4S+sEa/M=; b=VXXXzdByiPLHC1J/yL+PZ9Xh+Eccqv836/q5hovGuLkDaPyguoYarm2OlVYbzNBjeq 0e+bbvqOtxZnTDmnesr9DZWJagmA368OvXCHnzR0MR3k5whDjHHuYhWapUo9/LR/4Zcd Dubue9gnwp9vt/CCfD5PLs2361TiQhU91s2UPAgCRatM8/1O7ksrLBpSkCNnHyiRCLOT 0k9LXeIN1TjtWf8L1mfDt3kYU3YvWSmmXQx5OpuDgXwMx2677MWiRDZ3NgBu6DCisvPS X8Pqr53Ql2OvTbjyXDlr6KnkH7upESwpRuCInppEu/OWtXMnP+ZsdkKHZHSXRK+jMTkU rA9A== X-Gm-Message-State: AOJu0Yy2mnekdQ4xqY5QbqNA3iw2jf2t62znR8Dnt15N5RSOAuGcZEhx 3BigqEQZLiMAksFFkidGD2gtiPfSL0b3X1pthIrk05xq4y1UJO3M/yoS2Q== X-Gm-Gg: ASbGncvoMfb4OlMZpyQ8n9wU0YkU2nxZsyD/Z6xv/1NSoP9pQxkKEEjSHprHNDIRnxi /1OLWicEnS7ibhQQr65uU6iAo6uCpxeeV5c5T0Vf6fZ6mJVMIGX0WsAimMCfIo32MJc9/jHe6GF MJhlbnxuavM85Z6We0jhSmjUpb7F08lbOFx32I9vn8aA/8D/UsDzNqldpcwFznkUqRqTv1qZMcj oJiDVYdsDi7677pHv208aprPTiivW9zitY/vbpaBRguykAhpmar/7QFsczKJ9IE0n6JFenhAeQ0 /njxl4KTha/mYPz9ik+a7dZxzAu0zggPbKZM0N7uKpMpWToRWIL4dlrH8N7v X-Google-Smtp-Source: AGHT+IF9qDHqx17WP1ykRe2jis/XB2lInIrIUJQUOjGeDA0Lc5ZHXSpyn26AYLnA6QEVHI3LH1q5+Q== X-Received: by 2002:a17:90b:51cc:b0:2f6:d266:f462 with SMTP id 98e67ed59e1d1-30a4e698569mr24627183a91.35.1746517351605; Tue, 06 May 2025 00:42:31 -0700 (PDT) Received: from localhost.localdomain ([2405:6586:be0:0:83c8:d31d:2cec:f542]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a3480f0aasm14635860a91.35.2025.05.06.00.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 May 2025 00:42:31 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 6 May 2025 16:42:23 +0900 Message-ID: <9a8eec38e544b343c74c287b6a59c0be83fa0409.1746517343.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=maxim.cournoyer@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) This can be useful when evaluating a scheme->file store output for example, which has multiple top level expressions. * guix/ui.scm (read/eval): Also accept a port object as argument. Read and evaluate all expressions from input port or string. Change-Id: I0213706fa4824c3a8ffe5d93f44f263048cb62c2 --- guix/ui.scm | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index d462f7133e0..cd9eb1013d0 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -15,7 +15,7 @@ ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice ;;; Copyright © 2019, 2021 Simon Tournier ;;; Copyright © 2020 Arun Isaac -;;; Copyright © 2020 Maxim Cournoyer +;;; Copyright © 2020, 2025 Maxim Cournoyer ;;; Copyright © 2018 Steve Sprang ;;; Copyright © 2022 Taiju HIGASHI ;;; Copyright © 2022 Liliana Marie Prikler @@ -926,13 +926,18 @@ (define %guix-user-module module))) (define (read/eval str) - "Read and evaluate STR, raising an error if something goes wrong." - (let ((exp (catch #t - (lambda () - (call-with-input-string str read)) - (lambda args - (leave (G_ "failed to read expression ~s: ~s~%") - str args))))) + "Read and evaluate STR, which can also be a port, raising an error if +something goes wrong. STR may contain one or more expressions; the return +value is that of the last evaluated expression." + (define (read/safe port) + (catch #t + (lambda () + (read port)) + (lambda args + (leave (G_ "failed to read expression ~s: ~s~%") + str args)))) + + (define (eval/safe exp) (catch #t (lambda () (eval exp (force %guix-user-module))) @@ -956,7 +961,19 @@ (define (read/eval str) ((error args ...) (apply display-error #f (current-error-port) args)) (what? #f)) - (exit 1))))) + (exit 1)))) + + (let ((call-with-port-or-string (if (port? str) + call-with-port + call-with-input-string))) + (call-with-port-or-string + str + (lambda (port) + (let loop ((exp (read/safe port)) + (result #f)) + (if (eof-object? exp) + result + (loop (read/safe port) (eval/safe exp)))))))) (define (read/eval-package-expression str) "Read and evaluate STR and return the package it refers to, or exit an base-commit: a897159a7cdb521d64fd2a5034b6c895968a7f51 -- 2.49.0 From unknown Sun Jun 22 07:40:19 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#78277] [PATCH] ui: Allow evaluating multi-expressions strings with read/eval. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 May 2025 15:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78277 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxim Cournoyer Cc: 78277@debbugs.gnu.org, Josselin Poiret , Simon Tournier , Mathieu Othacehe , Tobias Geerinckx-Rice , Christopher Baines Received: via spool by 78277-submit@debbugs.gnu.org id=B78277.174663258812382 (code B ref 78277); Wed, 07 May 2025 15:44:02 +0000 Received: (at 78277) by debbugs.gnu.org; 7 May 2025 15:43:08 +0000 Received: from localhost ([127.0.0.1]:45852 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uCgvL-0003DS-CP for submit@debbugs.gnu.org; Wed, 07 May 2025 11:43:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46198) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uCgvJ-0003Cj-Ee for 78277@debbugs.gnu.org; Wed, 07 May 2025 11:43:05 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uCgvB-0001AS-Ed; Wed, 07 May 2025 11:42:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=TIF7l5+cNFQisXA1xU3itdK3n5tJqpJmS9KvrldjQQk=; b=fOiKnrsEKpF8Szv9W99v 4eVEIaggzM3llBWBwsRQ0AZtuxVyYkyWvBLFR/rRMv/tni4lXH8h9I/8XDwUKNjT+myZau39NIiAe 65i9NbMQG1YTmA1Ym+Rc2rLB+IAl4H8gEO9YdMcfsTS7+LITcrHe0ftIz/Dq0lNZwp+t6fPbqIM57 lHe55vpUJQnx9prFDJRllvJbmeVATmdj/g8V50nJA5Y045kY14bKsGP6Rk7LuhoPm+V9IAxCwKTW4 qxMD+tq7Pg4FrM7qDLvD7Eg5W9VKgoN3WfE805JAQpbxPXzxFQt+HspHeeYa2/549gDns/iyPB6Jv yljnJcMnm5Wptg==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <9a8eec38e544b343c74c287b6a59c0be83fa0409.1746517343.git.maxim.cournoyer@gmail.com> (Maxim Cournoyer's message of "Tue, 6 May 2025 16:42:23 +0900") References: <9a8eec38e544b343c74c287b6a59c0be83fa0409.1746517343.git.maxim.cournoyer@gmail.com> User-Agent: mu4e 1.12.9; emacs 29.4 X-URL: https://people.bordeaux.inria.fr/lcourtes/ X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu X-Revolutionary-Date: Octidi 18 =?UTF-8?Q?Flor=C3=A9al?= an 233 de la =?UTF-8?Q?R=C3=A9volution,?= jour de la Corbeille-d'or Date: Wed, 07 May 2025 17:27:50 +0200 Message-ID: <87ldr84f0p.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, Maxim Cournoyer writes: > This can be useful when evaluating a scheme->file store output for exampl= e, > which has multiple top level expressions. > > * guix/ui.scm (read/eval): Also accept a port object as argument. Read a= nd > evaluate all expressions from input port or string. > > Change-Id: I0213706fa4824c3a8ffe5d93f44f263048cb62c2 Very useful, thanks! Perhaps you can add a test for example with =E2=80=98guix build -e=E2=80=99= in =E2=80=98tests/guix-build.sh=E2=80=99? Otherwise, LGTM. Ludo=E2=80=99. From unknown Sun Jun 22 07:40:19 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Maxim Cournoyer Subject: bug#78277: closed (Re: [bug#78277] [PATCH] ui: Allow evaluating multi-expressions strings with read/eval.) Message-ID: References: <87ikm9ub9e.fsf@gmail.com> <9a8eec38e544b343c74c287b6a59c0be83fa0409.1746517343.git.maxim.cournoyer@gmail.com> X-Gnu-PR-Message: they-closed 78277 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 78277@debbugs.gnu.org Date: Fri, 09 May 2025 14:10:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1746799802-23466-1" This is a multi-part message in MIME format... ------------=_1746799802-23466-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #78277: [PATCH] ui: Allow evaluating multi-expressions strings with read/ev= al. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 78277@debbugs.gnu.org. --=20 78277: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D78277 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1746799802-23466-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 78277-done) by debbugs.gnu.org; 9 May 2025 14:09:17 +0000 Received: from localhost ([127.0.0.1]:38207 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uDOPc-00064j-Sr for submit@debbugs.gnu.org; Fri, 09 May 2025 10:09:17 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:43366) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uDOPY-00064I-Gv for 78277-done@debbugs.gnu.org; Fri, 09 May 2025 10:09:14 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-736c277331eso2941787b3a.1 for <78277-done@debbugs.gnu.org>; Fri, 09 May 2025 07:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746799746; x=1747404546; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0/6Z7DHYjerM0yJV4WKe6AuolZ/DHza55V9xZ6tLTo8=; b=lUFJk+Qyrwx64YCB4RXAGkxXiDWgeMQFQlGoHqwrfefij20eT4DFQ7EvxBegkPFEkK uhWzC/TZPUzo59/9JkPI/0CE273asd35yNLc/nRrUVDINZUbCPvQiI7O6+c+0Yc0VzCw eTJMQ9CA4DKa4NNTgpdcXF83epghxeoHpXkjOj66Xbf42LMnVbtb1LqT+A97abCSoogJ wIiRVHCYXzmbuygU2avgvblWQWkSgHfy1rYsF59AZvlmRsEe1J7AoJUgLWbVG5NIHzKd dXrS0N0ZDt19Hv1x8fSMW+q6yvr/UwqnTkzhf3LU/CFnJtSbPEYa0E5HzhNigldT7usS G9VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746799746; x=1747404546; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0/6Z7DHYjerM0yJV4WKe6AuolZ/DHza55V9xZ6tLTo8=; b=lStPoUv0FjFe53GrGlt3fwk3HGGT37iqPvT3E/bJohTMxcYGSYdE1kpKJe82YrHgAB rOWWtDOM+MjiE7PtIK6c7ZZchyFNatTYBYOdRnL/QlSI5JNq0HMs1aso1kGwChZCfMOA eNaevug0Okheg1h0/iW+4WaNqu4y4EiwxviJnYdF9LSbwfMz/KOkmuzDO87k511RRkuR Fgrwttp2/hGmbj19wE1yfhWJaVRBByzECjrBdrVWn2Z9mH+3OTT0f/wFumKdY5dDSTNx JIbi/5HZ7yQox1xBPjC37/Sp2IZ6TGo1D6FTOKhthG/AQGW9VUPUFCF+t5Mr5FVwcp00 745w== X-Gm-Message-State: AOJu0YxWG+dAG/c7IumW7v4lZQm+dlTYDekMDUI1zTCvSVp0C7Agr9nM RdqNk311QGRxHK+xm9VLnFh6zF3amBuxl8O4mDVlgjy/tdzIN5cm X-Gm-Gg: ASbGncuTDjLUrWT9G+qWtt9PxwYe8sVun/HJ3XG/Z8wqrzAGY91tYcld+GMxNBlU9/S jAstxOzckVlTw+mDrgndRqCMn4HSIX7xjnthobTXtNUug+XKX6EePmJwJEfkVk0EVr6KRwg7tL4 Y6NSWVrkqH0YRpXtQWZQ0Yri1kmtvWBqAXd3Qxe6/5rs/QRYUZbGnY7L83zIHU1nsZP0AxNdcSH 8QcepjBkTNmHx6iQucrw4BcX2NjOQBISL++oZw8scEnisZii85H4ojmwUcKBiCs2fcbCdiKCigD n56gAnCi6IvWaay26LL0SWWKfS5tnpl736CNJGg= X-Google-Smtp-Source: AGHT+IG5uTTWRCsiANLd2Vv9e2QyNrNTi1crMhsmlqlouooSkoRTneVwBj1qWoNtQBjL9aX1egInLw== X-Received: by 2002:a05:6a20:9f45:b0:1ee:d664:17a4 with SMTP id adf61e73a8af0-2159a002df0mr10632450637.10.1746799746278; Fri, 09 May 2025 07:09:06 -0700 (PDT) Received: from terra ([2405:6586:be0:0:83c8:d31d:2cec:f542]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b236de8839asm1401239a12.40.2025.05.09.07.09.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 May 2025 07:09:05 -0700 (PDT) From: Maxim Cournoyer To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#78277] [PATCH] ui: Allow evaluating multi-expressions strings with read/eval. In-Reply-To: <87ldr84f0p.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Wed, 07 May 2025 17:27:50 +0200") References: <9a8eec38e544b343c74c287b6a59c0be83fa0409.1746517343.git.maxim.cournoyer@gmail.com> <87ldr84f0p.fsf@gnu.org> Date: Fri, 09 May 2025 23:09:01 +0900 Message-ID: <87ikm9ub9e.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78277-done Cc: Josselin Poiret , Simon Tournier , Mathieu Othacehe , Tobias Geerinckx-Rice , 78277-done@debbugs.gnu.org, Christopher Baines X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi! Ludovic Court=C3=A8s writes: > Hi, > > Maxim Cournoyer writes: > >> This can be useful when evaluating a scheme->file store output for examp= le, >> which has multiple top level expressions. >> >> * guix/ui.scm (read/eval): Also accept a port object as argument. Read = and >> evaluate all expressions from input port or string. >> >> Change-Id: I0213706fa4824c3a8ffe5d93f44f263048cb62c2 > > Very useful, thanks! > > Perhaps you can add a test for example with =E2=80=98guix build -e=E2=80= =99 in > =E2=80=98tests/guix-build.sh=E2=80=99? Done! See commit 18ed22536d0. Thanks for the review! --=20 Maxim ------------=_1746799802-23466-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 6 May 2025 07:42:58 +0000 Received: from localhost ([127.0.0.1]:49317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uCCx7-00083C-SX for submit@debbugs.gnu.org; Tue, 06 May 2025 03:42:58 -0400 Received: from lists.gnu.org ([2001:470:142::17]:38814) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uCCx2-00081w-3B for submit@debbugs.gnu.org; Tue, 06 May 2025 03:42:53 -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 1uCCwl-0000LO-U1 for guix-patches@gnu.org; Tue, 06 May 2025 03:42:37 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uCCwk-0007Gm-5Z for guix-patches@gnu.org; Tue, 06 May 2025 03:42:35 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-b0b2d0b2843so4064840a12.2 for ; Tue, 06 May 2025 00:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746517352; x=1747122152; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nlCGfZZ8LgtWfXxSebXYnGZrqkK4+W1/l+V4S+sEa/M=; b=dGcop3HF4yTGioPrXvregoxt65C2PN16OJHUwAETyzkQJQZvF2dxm7RTgUfaaiRDcJ ck6VVywjKXSdxHRIDroIx5pQlsYsk8VPngG07RKfbiXASb3Si8rkeDLxF9B1PXsNzHWR 4Tr0/cGqhWu7qby1QhIiKCIUstEmEM9CnGH+XxwisDpOZ0EIWo6Qf9Somb1vYUScqobm Lgf5tgNdlyVRIvHxyjxpGpCUtnd7BcK7Zfr6jEXvNdNv9us+9kQwiEhHPhKv5LsPGDmh Y0qx3AACkit0u9lvf+6CMVK3Fp6oImAx7gsmsK6z3PjnezHPa2xAt7ozDgioXrJag9az JzZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746517352; x=1747122152; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nlCGfZZ8LgtWfXxSebXYnGZrqkK4+W1/l+V4S+sEa/M=; b=VXXXzdByiPLHC1J/yL+PZ9Xh+Eccqv836/q5hovGuLkDaPyguoYarm2OlVYbzNBjeq 0e+bbvqOtxZnTDmnesr9DZWJagmA368OvXCHnzR0MR3k5whDjHHuYhWapUo9/LR/4Zcd Dubue9gnwp9vt/CCfD5PLs2361TiQhU91s2UPAgCRatM8/1O7ksrLBpSkCNnHyiRCLOT 0k9LXeIN1TjtWf8L1mfDt3kYU3YvWSmmXQx5OpuDgXwMx2677MWiRDZ3NgBu6DCisvPS X8Pqr53Ql2OvTbjyXDlr6KnkH7upESwpRuCInppEu/OWtXMnP+ZsdkKHZHSXRK+jMTkU rA9A== X-Gm-Message-State: AOJu0Yy2mnekdQ4xqY5QbqNA3iw2jf2t62znR8Dnt15N5RSOAuGcZEhx 3BigqEQZLiMAksFFkidGD2gtiPfSL0b3X1pthIrk05xq4y1UJO3M/yoS2Q== X-Gm-Gg: ASbGncvoMfb4OlMZpyQ8n9wU0YkU2nxZsyD/Z6xv/1NSoP9pQxkKEEjSHprHNDIRnxi /1OLWicEnS7ibhQQr65uU6iAo6uCpxeeV5c5T0Vf6fZ6mJVMIGX0WsAimMCfIo32MJc9/jHe6GF MJhlbnxuavM85Z6We0jhSmjUpb7F08lbOFx32I9vn8aA/8D/UsDzNqldpcwFznkUqRqTv1qZMcj oJiDVYdsDi7677pHv208aprPTiivW9zitY/vbpaBRguykAhpmar/7QFsczKJ9IE0n6JFenhAeQ0 /njxl4KTha/mYPz9ik+a7dZxzAu0zggPbKZM0N7uKpMpWToRWIL4dlrH8N7v X-Google-Smtp-Source: AGHT+IF9qDHqx17WP1ykRe2jis/XB2lInIrIUJQUOjGeDA0Lc5ZHXSpyn26AYLnA6QEVHI3LH1q5+Q== X-Received: by 2002:a17:90b:51cc:b0:2f6:d266:f462 with SMTP id 98e67ed59e1d1-30a4e698569mr24627183a91.35.1746517351605; Tue, 06 May 2025 00:42:31 -0700 (PDT) Received: from localhost.localdomain ([2405:6586:be0:0:83c8:d31d:2cec:f542]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a3480f0aasm14635860a91.35.2025.05.06.00.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 May 2025 00:42:31 -0700 (PDT) From: Maxim Cournoyer To: guix-patches@gnu.org Subject: [PATCH] ui: Allow evaluating multi-expressions strings with read/eval. Date: Tue, 6 May 2025 16:42:23 +0900 Message-ID: <9a8eec38e544b343c74c287b6a59c0be83fa0409.1746517343.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-Debbugs-Cc: Christopher Baines , Josselin Poiret , Ludovic Courtès , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=maxim.cournoyer@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit Cc: Maxim Cournoyer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) This can be useful when evaluating a scheme->file store output for example, which has multiple top level expressions. * guix/ui.scm (read/eval): Also accept a port object as argument. Read and evaluate all expressions from input port or string. Change-Id: I0213706fa4824c3a8ffe5d93f44f263048cb62c2 --- guix/ui.scm | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index d462f7133e0..cd9eb1013d0 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -15,7 +15,7 @@ ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice ;;; Copyright © 2019, 2021 Simon Tournier ;;; Copyright © 2020 Arun Isaac -;;; Copyright © 2020 Maxim Cournoyer +;;; Copyright © 2020, 2025 Maxim Cournoyer ;;; Copyright © 2018 Steve Sprang ;;; Copyright © 2022 Taiju HIGASHI ;;; Copyright © 2022 Liliana Marie Prikler @@ -926,13 +926,18 @@ (define %guix-user-module module))) (define (read/eval str) - "Read and evaluate STR, raising an error if something goes wrong." - (let ((exp (catch #t - (lambda () - (call-with-input-string str read)) - (lambda args - (leave (G_ "failed to read expression ~s: ~s~%") - str args))))) + "Read and evaluate STR, which can also be a port, raising an error if +something goes wrong. STR may contain one or more expressions; the return +value is that of the last evaluated expression." + (define (read/safe port) + (catch #t + (lambda () + (read port)) + (lambda args + (leave (G_ "failed to read expression ~s: ~s~%") + str args)))) + + (define (eval/safe exp) (catch #t (lambda () (eval exp (force %guix-user-module))) @@ -956,7 +961,19 @@ (define (read/eval str) ((error args ...) (apply display-error #f (current-error-port) args)) (what? #f)) - (exit 1))))) + (exit 1)))) + + (let ((call-with-port-or-string (if (port? str) + call-with-port + call-with-input-string))) + (call-with-port-or-string + str + (lambda (port) + (let loop ((exp (read/safe port)) + (result #f)) + (if (eof-object? exp) + result + (loop (read/safe port) (eval/safe exp)))))))) (define (read/eval-package-expression str) "Read and evaluate STR and return the package it refers to, or exit an base-commit: a897159a7cdb521d64fd2a5034b6c895968a7f51 -- 2.49.0 ------------=_1746799802-23466-1--