Help with patch with delayed evaluation

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Nicolas Graves
Owner
unassigned
Submitted by
Nicolas Graves
Severity
normal
N
N
Nicolas Graves wrote on 1 Apr 2023 11:58
(address . bug-guix@gnu.org)
87ilefgbza.fsf@ngraves.fr
Hi Guix!

I'm struggling with the definition of the variants of the nerd-dictation
package. I'm sending a commit here.

I get the following error messages:
sox/wtype: unbound variable
while (gnu packages audio) and (gnu packages freedesktop) are indeed
imported.

Originally, I wasn't using delayed evaluation, but I thought it might
help, but it doesn't. I've tried to rebuild my local installation
totally (make clean-go, make clean, then bootstrap from there), but it
doesn't work better.

Thanks if you can help!

--
Best regards,
Nicolas Graves
N
N
Nicolas Graves wrote on 1 Apr 2023 12:05
[PATCH] gnu: nerd-dictation: Factor out wrapper. Add package variants.
(address . 62589@debbugs.gnu.org)(address . ngraves@ngraves.fr)
20230401100509.24723-1-ngraves@ngraves.fr
* gnu/packages/machine-learning.scm (nerd-dictation):
Avoid inputs pulseaudio and ydotool when not necessary.
Factor out wrapper make-nerd-dictation-package.
Add package variants :
- nerd-dictation/xdotool
- nerd-dictation/sox-xdotool
- nerd-dictation/sox-ydotool
- nerd-dictation/sox-wtype
---
gnu/packages/machine-learning.scm | 88 +++++++++++++++++++++----------
1 file changed, 60 insertions(+), 28 deletions(-)

Toggle diff (134 lines)
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 6c78b14fc6..16a5c1a7c4 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -17,6 +17,7 @@
;;; Copyright © 2020 Edouard Klein <edk@beaver-labs.com>
;;; Copyright © 2020, 2021, 2022, 2023 Vinicius Monego <monego@posteo.net>
;;; Copyright © 2020, 2021, 2022, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2022, 2023 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -63,6 +64,7 @@ (define-module (gnu packages machine-learning)
#:use-module (gnu packages cran)
#:use-module (gnu packages databases)
#:use-module (gnu packages dejagnu)
+ #:use-module (gnu packages freedesktop)
#:use-module (gnu packages gcc)
#:use-module (gnu packages gettext)
#:use-module (gnu packages gl)
@@ -106,6 +108,7 @@ (define-module (gnu packages machine-learning)
#:use-module (gnu packages xml)
#:use-module (gnu packages xdisorg)
#:use-module (gnu packages xorg)
+ #:use-module (srfi srfi-45)
#:use-module (ice-9 match))
(define-public fann
@@ -3864,7 +3867,6 @@ (define-public nerd-dictation
(add-after 'unpack 'chdir
(lambda _ (chdir "package/python"))))))
(propagated-inputs (list python-vosk))
- (inputs (list pulseaudio xdotool))
(home-page "https://github.com/ideasman42/nerd-dictation")
(synopsis "Offline speech-to-text for desktop Linux")
(description "\
@@ -3876,38 +3878,68 @@ (define-public nerd-dictation
@code{nerd-dictation begin} and @code{nerd-dictation end} commands.")
(license license:gpl3+))))
-(define-public nerd-dictation/wayland
- (package
- (inherit nerd-dictation)
- (name "nerd-dictation-wayland")
- (inputs (list bash-minimal nerd-dictation))
- (propagated-inputs (list ydotool sox))
- (build-system trivial-build-system)
- (arguments
- (list
- #:modules '((guix build utils))
- #:builder
- #~(begin
- (use-modules (guix build utils))
- (let* ((exe (string-append #$output "/bin/nerd-dictation"))
- (original-exe #$(file-append nerd-dictation
- "/bin/nerd-dictation"))
- (bash #$(this-package-input "bash-minimal"))
- (bash-exe (string-append bash "/bin/bash")))
- (mkdir-p (dirname exe))
- (call-with-output-file exe
- (lambda (port)
- (format port "#!~a
+(define* (make-nerd-dictation-package
+ input-tool output-tool
+ #:key (nerd-dictation-package nerd-dictation))
+ "Construct a nerd-dictation package for OUTPUT-TOOL."
+ (match-let* (((input-name output-name)
+ (map (lambda (tool)
+ (lazy
+ (delay (package-name (force tool)))))
+ (list input-tool output-tool))))
+ (package
+ (inherit nerd-dictation-package)
+ (name (string-append "nerd-dictation-"
+ (if (equal? (force input-name) "sox")
+ "sox-"
+ "")
+ (force output-name)))
+ (build-system trivial-build-system)
+ (arguments
+ (list
+ #:modules '((guix build utils))
+ #:builder
+ #~(begin
+ (use-modules (guix build utils))
+ (let* ((exe (string-append #$output "/bin/nerd-dictation"))
+ (original-exe #$(file-append
+ (this-package-input "nerd-dictation")
+ "/bin/nerd-dictation"))
+ (bash #$(this-package-input "bash-minimal"))
+ (bash-exe (string-append bash "/bin/bash")))
+ (mkdir-p (dirname exe))
+ (call-with-output-file exe
+ (lambda (port)
+ (format port "#!~a
if [ \"$1\" = begin ]
then
- exec ~a $@ --input=SOX --simulate-input-tool=YDOTOOL
+ exec ~a $@ --input=~a --simulate-input-tool=~a
else
exec ~a $@
fi"
- bash-exe
- original-exe
- original-exe)))
- (chmod exe #o555)))))))
+ bash-exe
+ original-exe
+ (if (equal? #$(force input-name) "pulseaudio")
+ "parec"
+ (string-upcase #$(force input-name)))
+ (string-upcase #$(force output-name))
+ original-exe)))
+ (chmod exe #o555)))))
+ (inputs (list bash-minimal nerd-dictation-package))
+ (propagated-inputs (list (force input-tool) (force output-tool))))))
+
+;; More variants are possible, but wayland without pipewire seems unlikely.
+(define-public nerd-dictation/xdotool
+ (make-nerd-dictation-package (delay pulseaudio) (delay xdotool)))
+
+(define-public nerd-dictation/sox-xdotool
+ (make-nerd-dictation-package (delay sox) (delay xdotool)))
+
+(define-public nerd-dictation/sox-ydotool
+ (make-nerd-dictation-package (delay sox) (delay ydotool)))
+
+(define-public nerd-dictation/sox-wtype
+ (make-nerd-dictation-package (delay sox) (delay wtype)))
(define-public python-brian2
(package
--
2.39.2
L
L
Ludovic Courtès wrote on 1 Apr 2023 12:28
Re: bug#62589: Help with patch with delayed evaluation
(name . Nicolas Graves)(address . ngraves@ngraves.fr)(address . 62589@debbugs.gnu.org)
87zg7rgaln.fsf_-_@gnu.org
Hi,

Nicolas Graves <ngraves@ngraves.fr> skribis:

Toggle quote (17 lines)
> +(define* (make-nerd-dictation-package
> + input-tool output-tool
> + #:key (nerd-dictation-package nerd-dictation))
> + "Construct a nerd-dictation package for OUTPUT-TOOL."
> + (match-let* (((input-name output-name)
> + (map (lambda (tool)
> + (lazy
> + (delay (package-name (force tool)))))
> + (list input-tool output-tool))))
> + (package
> + (inherit nerd-dictation-package)
> + (name (string-append "nerd-dictation-"
> + (if (equal? (force input-name) "sox")
> + "sox-"
> + "")
> + (force output-name)))

I don’t understand the details of what the patch does, but as a rule of
thumb, make sure you only ever inherit from packages defined in the same
module.

Perhaps that’s what was going wrong?

HTH,
Ludo’.
N
N
Nicolas Graves wrote on 1 Apr 2023 12:58
(name . Ludovic Courtès)(address . ludo@gnu.org)
87fs9jg974.fsf@ngraves.fr
On 2023-04-01 12:28, Ludovic Courtès wrote:

Toggle quote (25 lines)
> Hi,
>
> Nicolas Graves <ngraves@ngraves.fr> skribis:
>
>> +(define* (make-nerd-dictation-package
>> + input-tool output-tool
>> + #:key (nerd-dictation-package nerd-dictation))
>> + "Construct a nerd-dictation package for OUTPUT-TOOL."
>> + (match-let* (((input-name output-name)
>> + (map (lambda (tool)
>> + (lazy
>> + (delay (package-name (force tool)))))
>> + (list input-tool output-tool))))
>> + (package
>> + (inherit nerd-dictation-package)
>> + (name (string-append "nerd-dictation-"
>> + (if (equal? (force input-name) "sox")
>> + "sox-"
>> + "")
>> + (force output-name)))
>
> I don’t understand the details of what the patch does, but as a rule of
> thumb, make sure you only ever inherit from packages defined in the same
> module.

The patch defines a helper for defining variants of nerd-dictation. It
now supports wtype and I wasn't totally satisfied by international
support for ydotool, so I wanted to switch, but copying it make a lot of
repeated code.

I already defined such a helper with Liliana Marie Prinkler with
make-emacs-eval-in-repl, but this time I don't understand this error.

Josselin was suggesting a module import cycle, (gnu packages
machine-learning) is imported in (gnu packages audio), the error might
come from there.

Toggle quote (3 lines)
>
> Perhaps that’s what was going wrong?

I've tried inheriting from the above package direclty, doesn't seem to
be that.

Toggle quote (4 lines)
>
> HTH,
> Ludo’.

--
Best regards,
Nicolas Graves
N
N
Nicolas Graves wrote on 1 Apr 2023 17:27
(name . Ludovic Courtès)(address . ludo@gnu.org)
87cz4nfwr9.fsf@ngraves.fr
On 2023-04-01 12:58, Nicolas Graves wrote:

Toggle quote (49 lines)
> On 2023-04-01 12:28, Ludovic Courtès wrote:
>
>> Hi,
>>
>> Nicolas Graves <ngraves@ngraves.fr> skribis:
>>
>>> +(define* (make-nerd-dictation-package
>>> + input-tool output-tool
>>> + #:key (nerd-dictation-package nerd-dictation))
>>> + "Construct a nerd-dictation package for OUTPUT-TOOL."
>>> + (match-let* (((input-name output-name)
>>> + (map (lambda (tool)
>>> + (lazy
>>> + (delay (package-name (force tool)))))
>>> + (list input-tool output-tool))))
>>> + (package
>>> + (inherit nerd-dictation-package)
>>> + (name (string-append "nerd-dictation-"
>>> + (if (equal? (force input-name) "sox")
>>> + "sox-"
>>> + "")
>>> + (force output-name)))
>>
>> I don’t understand the details of what the patch does, but as a rule of
>> thumb, make sure you only ever inherit from packages defined in the same
>> module.
>
> The patch defines a helper for defining variants of nerd-dictation. It
> now supports wtype and I wasn't totally satisfied by international
> support for ydotool, so I wanted to switch, but copying it make a lot of
> repeated code.
>
> I already defined such a helper with Liliana Marie Prinkler with
> make-emacs-eval-in-repl, but this time I don't understand this error.
>
> Josselin was suggesting a module import cycle, (gnu packages
> machine-learning) is imported in (gnu packages audio), the error might
> come from there.
>
>>
>> Perhaps that’s what was going wrong?
>
> I've tried inheriting from the above package direclty, doesn't seem to
> be that.
>
>>
>> HTH,
>> Ludo’.

After thinking and experimenting, I think what I'm trying to do is not
possible in this file. This is for a record if someone has the same kind
of issue in the future.

When I include sox or wtype as a regular input, it works fine. But it
doesn't work when called from another function, I think the issue is
indeed the same as when inheriting from a package.

Now, there is the counterexample of the make-emacs-eval-in-repl
function. IIUC, this example works with delayed evaluation because all
the packages it calls are defined *in the same file*. To test this, on
way could be to test inheritance on a package defined in the same file
but after the inheriting package definition. IIRC, it doesn't work, but
might when using delayed evaluation.

This aside, the packages I'm trying to load are outside the file, and
this is probably the reason why it works for make-emacs-eval-in-repl and
not this function.

I will try to circumvent the issue by factorising less, maybe just the
gexp, but not propagated-inputs.

--
Best regards,
Nicolas Graves
N
N
Nicolas Graves wrote on 1 Apr 2023 19:32
[PATCH] gnu: nerd-dictation: Factor out wrapper. Add package variants.
(address . 62589@debbugs.gnu.org)(address . ngraves@ngraves.fr)
20230401173239.26588-1-ngraves@ngraves.fr
* gnu/packages/machine-learning.scm (nerd-dictation):
Avoid inputs pulseaudio and ydotool when not necessary.
Factor out wrapper make-nerd-dictation-package.
Add package variants :
- nerd-dictation/xdotool
- nerd-dictation/sox-xdotool
- nerd-dictation/sox-ydotool
- nerd-dictation/sox-wtype
---
gnu/packages/machine-learning.scm | 97 ++++++++++++++++++++++---------
1 file changed, 69 insertions(+), 28 deletions(-)

Toggle diff (136 lines)
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 6c78b14fc6..4383f3fef3 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -17,6 +17,7 @@
;;; Copyright © 2020 Edouard Klein <edk@beaver-labs.com>
;;; Copyright © 2020, 2021, 2022, 2023 Vinicius Monego <monego@posteo.net>
;;; Copyright © 2020, 2021, 2022, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2022, 2023 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -63,6 +64,7 @@ (define-module (gnu packages machine-learning)
#:use-module (gnu packages cran)
#:use-module (gnu packages databases)
#:use-module (gnu packages dejagnu)
+ #:use-module (gnu packages freedesktop)
#:use-module (gnu packages gcc)
#:use-module (gnu packages gettext)
#:use-module (gnu packages gl)
@@ -3864,7 +3866,6 @@ (define-public nerd-dictation
(add-after 'unpack 'chdir
(lambda _ (chdir "package/python"))))))
(propagated-inputs (list python-vosk))
- (inputs (list pulseaudio xdotool))
(home-page "https://github.com/ideasman42/nerd-dictation")
(synopsis "Offline speech-to-text for desktop Linux")
(description "\
@@ -3876,38 +3877,78 @@ (define-public nerd-dictation
@code{nerd-dictation begin} and @code{nerd-dictation end} commands.")
(license license:gpl3+))))
-(define-public nerd-dictation/wayland
- (package
- (inherit nerd-dictation)
- (name "nerd-dictation-wayland")
- (inputs (list bash-minimal nerd-dictation))
- (propagated-inputs (list ydotool sox))
- (build-system trivial-build-system)
- (arguments
- (list
- #:modules '((guix build utils))
- #:builder
- #~(begin
- (use-modules (guix build utils))
- (let* ((exe (string-append #$output "/bin/nerd-dictation"))
- (original-exe #$(file-append nerd-dictation
- "/bin/nerd-dictation"))
- (bash #$(this-package-input "bash-minimal"))
- (bash-exe (string-append bash "/bin/bash")))
- (mkdir-p (dirname exe))
- (call-with-output-file exe
- (lambda (port)
- (format port "#!~a
+(define (nerd-dictation-gexp input-name output-name bash nerd-dictation)
+ #~(begin
+ (use-modules (guix build utils))
+ (let* ((exe (string-append %output "/bin/nerd-dictation"))
+ (nerd-dictation-exe
+ #$(file-append nerd-dictation "/bin/nerd-dictation")))
+ (mkdir-p (dirname exe))
+ (call-with-output-file exe
+ (lambda (port)
+ (format port "#!~a
if [ \"$1\" = begin ]
then
- exec ~a $@ --input=SOX --simulate-input-tool=YDOTOOL
+ exec ~a $@ --input=~a --simulate-input-tool=~a
else
exec ~a $@
fi"
- bash-exe
- original-exe
- original-exe)))
- (chmod exe #o555)))))))
+ #$(file-append bash "/bin/bash")
+ nerd-dictation-exe
+ #$input-name
+ #$output-name
+ nerd-dictation-exe)))
+ (chmod exe #o555))))
+
+(define-public nerd-dictation/xdotool
+ (package
+ (inherit nerd-dictation)
+ (name "nerd-dictation-xdotool")
+ (build-system trivial-build-system)
+ (arguments (list
+ #:modules '((guix build utils))
+ #:builder
+ (nerd-dictation-gexp "PAREC" "XDOTOOL"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
+ (inputs (list bash-minimal nerd-dictation))
+ (propagated-inputs (list pulseaudio xdotool))))
+
+(define-public nerd-dictation/sox-xdotool
+ (package
+ (inherit nerd-dictation/xdotool)
+ (name "nerd-dictation-sox-xdotool")
+ (arguments (list
+ #:modules '((guix build utils))
+ #:builder
+ (nerd-dictation-gexp "SOX" "XDOTOOL"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
+ (propagated-inputs (list sox xdotool))))
+
+(define-public nerd-dictation/sox-ydotool
+ (package
+ (inherit nerd-dictation/xdotool)
+ (name "nerd-dictation-sox-ydotool")
+ (arguments (list
+ #:modules '((guix build utils))
+ #:builder
+ (nerd-dictation-gexp "SOX" "YDOTOOL"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
+ (propagated-inputs (list sox ydotool))))
+
+(define-public nerd-dictation/sox-wtype
+ (package
+ (inherit nerd-dictation/xdotool)
+ (name "nerd-dictation-sox-wtype")
+ (arguments (list
+ #:modules '((guix build utils))
+ #:builder
+ (nerd-dictation-gexp "SOX" "WTYPE"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
+ (propagated-inputs (list sox wtype))))
(define-public python-brian2
(package
--
2.39.2
N
N
Nicolas Graves wrote on 17 Apr 2023 17:41
Re: bug#62589: Help with patch with delayed evaluation
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 62589@debbugs.gnu.org)
87wn2att23.fsf@ngraves.fr
Hey Ludo,

I've managed to do what I wanted here, just a little reminder if you can
review this ;)

--
Best regards,
Nicolas Graves
L
L
Ludovic Courtès wrote on 24 Apr 2023 22:53
(name . Nicolas Graves)(address . ngraves@ngraves.fr)(address . 62589-done@debbugs.gnu.org)
87jzy10zpo.fsf_-_@gnu.org
Hi Nicolas,

Nicolas Graves <ngraves@ngraves.fr> skribis:

Toggle quote (12 lines)
> * gnu/packages/machine-learning.scm (nerd-dictation):
> Avoid inputs pulseaudio and ydotool when not necessary.
> Factor out wrapper make-nerd-dictation-package.
> Add package variants :
> - nerd-dictation/xdotool
> - nerd-dictation/sox-xdotool
> - nerd-dictation/sox-ydotool
> - nerd-dictation/sox-wtype
> ---
> gnu/packages/machine-learning.scm | 97 ++++++++++++++++++++++---------
> 1 file changed, 69 insertions(+), 28 deletions(-)

Applied with the changes below (using ‘with-imported-modules’ instead of
passing #:modules, and #$output instead of the now-deprecated
‘%output’).

I also tweaked the commit log according to our conventions.

Thank you,
Ludo’.
Toggle diff (118 lines)
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 84b40e7b9b..c4dc668b82 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -3882,39 +3882,40 @@ (define-public nerd-dictation
(license license:gpl2+))))
(define (nerd-dictation-gexp input-name output-name bash nerd-dictation)
- #~(begin
- (use-modules (guix build utils))
- (let* ((exe (string-append %output "/bin/nerd-dictation"))
- (nerd-dictation-exe
- #$(file-append nerd-dictation "/bin/nerd-dictation")))
- (mkdir-p (dirname exe))
- (call-with-output-file exe
- (lambda (port)
- (format port "#!~a
+ (with-imported-modules '((guix build utils))
+ #~(begin
+ (use-modules (guix build utils))
+
+ (let* ((exe (string-append #$output "/bin/nerd-dictation"))
+ (nerd-dictation-exe
+ #$(file-append nerd-dictation "/bin/nerd-dictation")))
+ (mkdir-p (dirname exe))
+ (call-with-output-file exe
+ (lambda (port)
+ (format port "#!~a
if [ \"$1\" = begin ]
then
exec ~a $@ --input=~a --simulate-input-tool=~a
else
exec ~a $@
fi"
- #$(file-append bash "/bin/bash")
- nerd-dictation-exe
- #$input-name
- #$output-name
- nerd-dictation-exe)))
- (chmod exe #o555))))
+ #$(file-append bash "/bin/bash")
+ nerd-dictation-exe
+ #$input-name
+ #$output-name
+ nerd-dictation-exe)))
+ (chmod exe #o555)))))
(define-public nerd-dictation/xdotool
(package
(inherit nerd-dictation)
(name "nerd-dictation-xdotool")
(build-system trivial-build-system)
- (arguments (list
- #:modules '((guix build utils))
- #:builder
- (nerd-dictation-gexp "PAREC" "XDOTOOL"
- (this-package-input "bash-minimal")
- (this-package-input "nerd-dictation"))))
+ (arguments
+ (list #:builder
+ (nerd-dictation-gexp "PAREC" "XDOTOOL"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
(inputs (list bash-minimal nerd-dictation))
(propagated-inputs (list pulseaudio xdotool))))
@@ -3922,36 +3923,33 @@ (define-public nerd-dictation/sox-xdotool
(package
(inherit nerd-dictation/xdotool)
(name "nerd-dictation-sox-xdotool")
- (arguments (list
- #:modules '((guix build utils))
- #:builder
- (nerd-dictation-gexp "SOX" "XDOTOOL"
- (this-package-input "bash-minimal")
- (this-package-input "nerd-dictation"))))
+ (arguments
+ (list #:builder
+ (nerd-dictation-gexp "SOX" "XDOTOOL"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
(propagated-inputs (list sox xdotool))))
(define-public nerd-dictation/sox-ydotool
(package
(inherit nerd-dictation/xdotool)
(name "nerd-dictation-sox-ydotool")
- (arguments (list
- #:modules '((guix build utils))
- #:builder
- (nerd-dictation-gexp "SOX" "YDOTOOL"
- (this-package-input "bash-minimal")
- (this-package-input "nerd-dictation"))))
+ (arguments
+ (list #:builder
+ (nerd-dictation-gexp "SOX" "YDOTOOL"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
(propagated-inputs (list sox ydotool))))
(define-public nerd-dictation/sox-wtype
(package
(inherit nerd-dictation/xdotool)
(name "nerd-dictation-sox-wtype")
- (arguments (list
- #:modules '((guix build utils))
- #:builder
- (nerd-dictation-gexp "SOX" "WTYPE"
- (this-package-input "bash-minimal")
- (this-package-input "nerd-dictation"))))
+ (arguments
+ (list #:builder
+ (nerd-dictation-gexp "SOX" "WTYPE"
+ (this-package-input "bash-minimal")
+ (this-package-input "nerd-dictation"))))
(propagated-inputs (list sox wtype))))
(define-public python-brian2
Closed
?