GNU bug report logs -
#78277
[PATCH] ui: Allow evaluating multi-expressions strings with read/eval.
Previous Next
To reply to this bug, email your comments to 78277 AT debbugs.gnu.org.
There is no need to reopen the bug first.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org
:
bug#78277
; Package
guix-patches
.
(Tue, 06 May 2025 07:43:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org
.
(Tue, 06 May 2025 07:43:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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 <me <at> tobias.gr>
;;; Copyright © 2019, 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
;;; Copyright © 2020 Arun Isaac <arunisaac <at> systemreboot.net>
-;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
+;;; Copyright © 2020, 2025 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
;;; Copyright © 2018 Steve Sprang <scs <at> stevesprang.com>
;;; Copyright © 2022 Taiju HIGASHI <higashi <at> taiju.info>
;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler <at> gmail.com>
@@ -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
Information forwarded
to
guix-patches <at> gnu.org
:
bug#78277
; Package
guix-patches
.
(Wed, 07 May 2025 15:44:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 78277 <at> debbugs.gnu.org (full text, mbox):
Hi,
Maxim Cournoyer <maxim.cournoyer <at> gmail.com> writes:
> 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
Very useful, thanks!
Perhaps you can add a test for example with ‘guix build -e’ in
‘tests/guix-build.sh’?
Otherwise, LGTM.
Ludo’.
Reply sent
to
Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
:
You have taken responsibility.
(Fri, 09 May 2025 14:10:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
:
bug acknowledged by developer.
(Fri, 09 May 2025 14:10:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 78277-done <at> debbugs.gnu.org (full text, mbox):
Hi!
Ludovic Courtès <ludo <at> gnu.org> writes:
> Hi,
>
> Maxim Cournoyer <maxim.cournoyer <at> gmail.com> writes:
>
>> 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
>
> Very useful, thanks!
>
> Perhaps you can add a test for example with ‘guix build -e’ in
> ‘tests/guix-build.sh’?
Done! See commit 18ed22536d0. Thanks for the review!
--
Maxim
This bug report was last modified 6 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.