GNU bug report logs - #40373
[PATCH] guix: new command "guix run-script"

Previous Next

Package: guix-patches;

Reported by: Konrad Hinsen <konrad.hinsen <at> fastmail.net>

Date: Wed, 1 Apr 2020 14:10:01 UTC

Severity: normal

Tags: patch

Done: zimoun <zimon.toutoune <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 40373 in the body.
You can then email your comments to 40373 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Wed, 01 Apr 2020 14:10:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Konrad Hinsen <konrad.hinsen <at> fastmail.net>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 01 Apr 2020 14:10:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: guix-patches <at> gnu.org
Subject: [PATCH] guix: new command "guix run-script"
Date: Wed, 01 Apr 2020 16:09:11 +0200
* guix/scripts/run-script.scm: New file.
* Makefile.am: (MODULES): Add it.
* doc/guix.texi: Document "guix time-machine"
---
 Makefile.am                 |   1 +
 doc/guix.texi               |  32 +++++++++++
 guix/scripts/run-script.scm | 106 ++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 guix/scripts/run-script.scm

diff --git a/Makefile.am b/Makefile.am
index 344ecdbc42..28ac7344e8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -283,6 +283,7 @@ MODULES =					\
   guix/scripts/container/exec.scm		\
   guix/scripts/deploy.scm			\
   guix/scripts/time-machine.scm			\
+  guix/scripts/run-script.scm			\
   guix.scm					\
   $(GNU_SYSTEM_MODULES)
 
diff --git a/doc/guix.texi b/doc/guix.texi
index 8cb85fe62c..0a64af24dc 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -235,6 +235,7 @@ Programming Interface
 * The Store Monad::             Purely functional interface to the store.
 * G-Expressions::               Manipulating build expressions.
 * Invoking guix repl::          Fiddling with Guix interactively.
+* Invoking guix run-script::    Running Guix scripts.
 
 Defining Packages
 
@@ -5347,6 +5348,7 @@ package definitions.
 * The Store Monad::             Purely functional interface to the store.
 * G-Expressions::               Manipulating build expressions.
 * Invoking guix repl::          Fiddling with Guix interactively.
+* Invoking guix run-script::    Running Guix scripts.
 @end menu
 
 @node Package Modules
@@ -8121,6 +8123,36 @@ Inhibit loading of the @file{~/.guile} file.  By default, that
 configuration file is loaded when spawning a @code{guile} REPL.
 @end table
 
+@node Invoking guix run-script
+@section Invoking @command{guix run-script}
+
+@cindex script
+
+The @command{guix run-script} command executes a Guile script
+(@pxref{Running Guile Scripts,,, guile, GNU Guile Reference Manual}).
+Compared to just launching the @command{guile} command,
+@command{guix run-script} guarantees that all the Guix modules
+and all its dependencies are available in the search path.
+
+The general syntax is:
+
+@example
+guix run-script @var{options} @var{file}
+@end example
+
+The available options are as follows:
+
+@table @code
+@item --load-path=@var{directory}
+@itemx -L @var{directory}
+Add @var{directory} to the front of the package module search path
+(@pxref{Package Modules}).
+
+@item -q
+Inhibit loading of the @file{~/.guile} file.  By default, that
+configuration file is loaded before executing the script.
+@end table
+
 @c *********************************************************************
 @node Utilities
 @chapter Utilities
diff --git a/guix/scripts/run-script.scm b/guix/scripts/run-script.scm
new file mode 100644
index 0000000000..2e948da85f
--- /dev/null
+++ b/guix/scripts/run-script.scm
@@ -0,0 +1,106 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen <at> fastmail.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix scripts run-script)
+  #:use-module (guix ui)
+  #:use-module (guix scripts)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-37)
+  #:use-module (ice-9 match)
+  #:export (guix-run-script))
+
+;;; Commentary:
+;;;
+;;; This command allows to run Guile scripts in an environment
+;;; that contains all the modules comprising Guix.
+
+(define %default-options
+  '())
+
+(define %options
+  (list (option '(#\h "help") #f #f
+                (lambda args
+                  (show-help)
+                  (exit 0)))
+        (option '(#\V "version") #f #f
+                (lambda args
+                  (show-version-and-exit "guix run-script")))
+        (option '(#\q) #f #f
+                (lambda (opt name arg result)
+                  (alist-cons 'ignore-dot-guile? #t result)))
+        (option '(#\L "load-path") #t #f
+                (lambda (opt name arg result)
+                  ;; XXX: Imperatively modify the search paths.
+                  (set! %load-path (cons arg %load-path))
+                  (set! %load-compiled-path (cons arg %load-compiled-path))
+                  result))))
+
+
+(define (show-help)
+  (display (G_ "Usage: guix run-script [OPTIONS...] FILE
+Run FILE as a Guile script in the Guix execution environment.\n"))
+  (display (G_ "
+  -q                     inhibit loading of ~/.guile"))
+  (newline)
+  (display (G_ "
+  -L, --load-path=DIR    prepend DIR to the package module search path"))
+  (newline)
+  (display (G_ "
+  -h, --help             display this help and exit"))
+  (display (G_ "
+  -V, --version          display version information and exit"))
+  (newline)
+  (show-bug-report-information))
+
+(define user-module
+  ;; Module where we execute user code.
+  (let ((module (resolve-module '(guix-user) #f #f #:ensure #t)))
+    (beautify-user-module! module)
+    module))
+
+
+(define (guix-run-script . args)
+  (define opts
+    (args-fold* args %options
+                (lambda (opt name arg result)
+                  (leave (G_ "~A: unrecognized option~%") name))
+                (lambda (arg result)
+                  (when (assq 'argument result)
+                    (leave (G_ "~A: extraneous argument~%") arg))
+                  (alist-cons 'argument arg result))
+                %default-options))
+
+  (define script
+    (or (assq-ref opts 'argument)
+        (leave (G_ "no script filename specified~%"))))
+
+  (define user-config
+    (and=> (getenv "HOME")
+           (lambda (home)
+             (string-append home "/.guile"))))
+
+  (with-error-handling
+    (save-module-excursion
+     (lambda ()
+       (set-current-module user-module)
+       (when (and (not (assoc-ref opts 'ignore-dot-guile?))
+                  user-config
+                  (file-exists? user-config))
+         (load user-config))
+       (load script)))))
-- 
2.26.0




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Wed, 01 Apr 2020 21:01:02 GMT) Full text and rfc822 format available.

Message #8 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Wed, 01 Apr 2020 23:00:29 +0200
Hi Konrad,

Konrad Hinsen <konrad.hinsen <at> fastmail.net> skribis:

> +The @command{guix run-script} command executes a Guile script
> +(@pxref{Running Guile Scripts,,, guile, GNU Guile Reference Manual}).
> +Compared to just launching the @command{guile} command,
> +@command{guix run-script} guarantees that all the Guix modules
> +and all its dependencies are available in the search path.

What about making that just a new ‘-s’ flag for ‘guix repl’ (just like
Guile’s ‘-s’ flag)?  ‘-q’ should always be implied when doing that.

Now, this wouldn’t be usable as a shebang due to the fact that only one
argument is allowed, unless we do some extra argument tokenizing.

Thanks,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 02 Apr 2020 07:14:02 GMT) Full text and rfc822 format available.

Message #11 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 02 Apr 2020 09:13:23 +0200
Hi Ludo,

> What about making that just a new ‘-s’ flag for ‘guix repl’ (just like
> Guile’s ‘-s’ flag)?  ‘-q’ should always be implied when doing that.
>
> Now, this wouldn’t be usable as a shebang due to the fact that only one
> argument is allowed, unless we do some extra argument tokenizing.

That is one reason why I opted for a separate command.

The other is that I am in tutorial-driven development mode: I need "guix
run-script" in order to be able to insert my own scripts (for analyzing
dependencies) into a Guix tutorial for an upcoming MOOC. So I need to
make sure that people can run my scripts easily, but also that they
understand what they are doing. A command that does something else than
its name suggests, with a similarity that is only visible to experts,
is no good for use in a tutorial.

BTW, I opted for a lengthy name ("run-script" rather than just "run" or
"script") according to the principle that short words should be left for
frequently used concepts (a principle respected by human languages, but
also by Lisp tradition).

I am of course aware that much of the code in "run-script" is the same
as in "repl", which is not good. But I'd rather think about a better
framework for code sharing among Guix scripts than about pushing too
much semantic differences into obscure options. An example would be
reusable "option clusters", such as "options for Guile" or "options for
channels".

Cheers,
  Konrad.




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 02 Apr 2020 09:09:01 GMT) Full text and rfc822 format available.

Message #14 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 2 Apr 2020 11:08:15 +0200
Hi Konrad,

On Wed, 1 Apr 2020 at 16:10, Konrad Hinsen <konrad.hinsen <at> fastmail.net> wrote:
>
> * guix/scripts/run-script.scm: New file.
> * Makefile.am: (MODULES): Add it.
> * doc/guix.texi: Document "guix time-machine"

Wrong copy/paste?
Is it not "run-script" instead of "time-machine"?


> --- /dev/null
> +++ b/guix/scripts/run-script.scm
> @@ -0,0 +1,106 @@
> +;;; GNU Guix --- Functional package management for GNU
> +;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
> +;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen <at> fastmail.net>

Why Copyright 2018, 2019 is the file is new?
And why Ludo is mentioned here?



Cheers,
simon




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 02 Apr 2020 09:18:01 GMT) Full text and rfc822 format available.

Message #17 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 2 Apr 2020 11:17:19 +0200
Hi Konrad,

On Thu, 2 Apr 2020 at 09:14, Konrad Hinsen <konrad.hinsen <at> fastmail.net> wrote:

> > What about making that just a new ‘-s’ flag for ‘guix repl’ (just like
> > Guile’s ‘-s’ flag)?  ‘-q’ should always be implied when doing that.
> >
> > Now, this wouldn’t be usable as a shebang due to the fact that only one
> > argument is allowed, unless we do some extra argument tokenizing.
>
> That is one reason why I opted for a separate command.
>
> The other is that I am in tutorial-driven development mode: I need "guix
> run-script" in order to be able to insert my own scripts (for analyzing
> dependencies) into a Guix tutorial for an upcoming MOOC. So I need to
> make sure that people can run my scripts easily, but also that they
> understand what they are doing. A command that does something else than
> its name suggests, with a similarity that is only visible to experts,
> is no good for use in a tutorial.
>
> BTW, I opted for a lengthy name ("run-script" rather than just "run" or
> "script") according to the principle that short words should be left for
> frequently used concepts (a principle respected by human languages, but
> also by Lisp tradition).
>
> I am of course aware that much of the code in "run-script" is the same
> as in "repl", which is not good. But I'd rather think about a better
> framework for code sharing among Guix scripts than about pushing too
> much semantic differences into obscure options. An example would be
> reusable "option clusters", such as "options for Guile" or "options for
> channels".

Initially, I thought the same as Ludo: "run-script" should be an
option to "repl". And I understand your UI concerns.

Maybe, we could deprecated "repl" and add "run" with:
 - guix run <file> (same than the "guix run-script" proposal)
 - guix run or guix run --repl doing the what "guix repl" does.

The new command "guix run" could have more or less the same option
than "guile" but prepending all the paths correctly. I mean we need
something like "guix name-it <otpions>" mimicking "guile <options>"
adding the correct Guix modules, IMHO.


BTW, thank you for this. Because it was missing in my toolbox and I
was annoyed until now.


Cheers,
simon




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 02 Apr 2020 09:22:01 GMT) Full text and rfc822 format available.

Message #20 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 02 Apr 2020 11:21:26 +0200
Hi Simon,

> Wrong copy/paste?

Exactly. Same for the next point. Update coming.

Cheers,
  Konrad.




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 02 Apr 2020 09:27:01 GMT) Full text and rfc822 format available.

Message #23 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: 40373 <at> debbugs.gnu.org
Subject: [PATCH] guix: new command "guix run-script"
Date: Thu, 02 Apr 2020 11:25:44 +0200
* guix/scripts/run-script.scm: New file.
* Makefile.am: (MODULES): Add it.
* doc/guix.texi: Document "guix run-script"
---
 Makefile.am                 |   1 +
 doc/guix.texi               |  32 +++++++++++
 guix/scripts/run-script.scm | 105 ++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 guix/scripts/run-script.scm

diff --git a/Makefile.am b/Makefile.am
index 344ecdbc42..28ac7344e8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -283,6 +283,7 @@ MODULES =					\
   guix/scripts/container/exec.scm		\
   guix/scripts/deploy.scm			\
   guix/scripts/time-machine.scm			\
+  guix/scripts/run-script.scm			\
   guix.scm					\
   $(GNU_SYSTEM_MODULES)
 
diff --git a/doc/guix.texi b/doc/guix.texi
index 8cb85fe62c..0a64af24dc 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -235,6 +235,7 @@ Programming Interface
 * The Store Monad::             Purely functional interface to the store.
 * G-Expressions::               Manipulating build expressions.
 * Invoking guix repl::          Fiddling with Guix interactively.
+* Invoking guix run-script::    Running Guix scripts.
 
 Defining Packages
 
@@ -5347,6 +5348,7 @@ package definitions.
 * The Store Monad::             Purely functional interface to the store.
 * G-Expressions::               Manipulating build expressions.
 * Invoking guix repl::          Fiddling with Guix interactively.
+* Invoking guix run-script::    Running Guix scripts.
 @end menu
 
 @node Package Modules
@@ -8121,6 +8123,36 @@ Inhibit loading of the @file{~/.guile} file.  By default, that
 configuration file is loaded when spawning a @code{guile} REPL.
 @end table
 
+@node Invoking guix run-script
+@section Invoking @command{guix run-script}
+
+@cindex script
+
+The @command{guix run-script} command executes a Guile script
+(@pxref{Running Guile Scripts,,, guile, GNU Guile Reference Manual}).
+Compared to just launching the @command{guile} command,
+@command{guix run-script} guarantees that all the Guix modules
+and all its dependencies are available in the search path.
+
+The general syntax is:
+
+@example
+guix run-script @var{options} @var{file}
+@end example
+
+The available options are as follows:
+
+@table @code
+@item --load-path=@var{directory}
+@itemx -L @var{directory}
+Add @var{directory} to the front of the package module search path
+(@pxref{Package Modules}).
+
+@item -q
+Inhibit loading of the @file{~/.guile} file.  By default, that
+configuration file is loaded before executing the script.
+@end table
+
 @c *********************************************************************
 @node Utilities
 @chapter Utilities
diff --git a/guix/scripts/run-script.scm b/guix/scripts/run-script.scm
new file mode 100644
index 0000000000..2e0ef2aff3
--- /dev/null
+++ b/guix/scripts/run-script.scm
@@ -0,0 +1,105 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen <at> fastmail.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix scripts run-script)
+  #:use-module (guix ui)
+  #:use-module (guix scripts)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-37)
+  #:use-module (ice-9 match)
+  #:export (guix-run-script))
+
+;;; Commentary:
+;;;
+;;; This command allows to run Guile scripts in an environment
+;;; that contains all the modules comprising Guix.
+
+(define %default-options
+  '())
+
+(define %options
+  (list (option '(#\h "help") #f #f
+                (lambda args
+                  (show-help)
+                  (exit 0)))
+        (option '(#\V "version") #f #f
+                (lambda args
+                  (show-version-and-exit "guix run-script")))
+        (option '(#\q) #f #f
+                (lambda (opt name arg result)
+                  (alist-cons 'ignore-dot-guile? #t result)))
+        (option '(#\L "load-path") #t #f
+                (lambda (opt name arg result)
+                  ;; XXX: Imperatively modify the search paths.
+                  (set! %load-path (cons arg %load-path))
+                  (set! %load-compiled-path (cons arg %load-compiled-path))
+                  result))))
+
+
+(define (show-help)
+  (display (G_ "Usage: guix run-script [OPTIONS...] FILE
+Run FILE as a Guile script in the Guix execution environment.\n"))
+  (display (G_ "
+  -q                     inhibit loading of ~/.guile"))
+  (newline)
+  (display (G_ "
+  -L, --load-path=DIR    prepend DIR to the package module search path"))
+  (newline)
+  (display (G_ "
+  -h, --help             display this help and exit"))
+  (display (G_ "
+  -V, --version          display version information and exit"))
+  (newline)
+  (show-bug-report-information))
+
+(define user-module
+  ;; Module where we execute user code.
+  (let ((module (resolve-module '(guix-user) #f #f #:ensure #t)))
+    (beautify-user-module! module)
+    module))
+
+
+(define (guix-run-script . args)
+  (define opts
+    (args-fold* args %options
+                (lambda (opt name arg result)
+                  (leave (G_ "~A: unrecognized option~%") name))
+                (lambda (arg result)
+                  (when (assq 'argument result)
+                    (leave (G_ "~A: extraneous argument~%") arg))
+                  (alist-cons 'argument arg result))
+                %default-options))
+
+  (define script
+    (or (assq-ref opts 'argument)
+        (leave (G_ "no script filename specified~%"))))
+
+  (define user-config
+    (and=> (getenv "HOME")
+           (lambda (home)
+             (string-append home "/.guile"))))
+
+  (with-error-handling
+    (save-module-excursion
+     (lambda ()
+       (set-current-module user-module)
+       (when (and (not (assoc-ref opts 'ignore-dot-guile?))
+                  user-config
+                  (file-exists? user-config))
+         (load user-config))
+       (load script)))))
-- 
2.26.0




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 02 Apr 2020 09:38:02 GMT) Full text and rfc822 format available.

Message #26 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 02 Apr 2020 11:37:18 +0200
Hi Simon,

> Maybe, we could deprecated "repl" and add "run" with:
>  - guix run <file> (same than the "guix run-script" proposal)
>  - guix run or guix run --repl doing the what "guix repl" does.

Yes, unifying the two functionalities under a new name is an interesting
options.

Could we go for "guix guile" and make it option-compatible with plain
Guile as much as possible? Just an idea, I am not sure it's a good one!
Guile can already be a pain in a shebang line.

Cheers,
  Konrad




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Fri, 03 Apr 2020 09:19:01 GMT) Full text and rfc822 format available.

Message #29 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: 40373 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>,
 zimoun <zimon.toutoune <at> gmail.com>
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Fri, 03 Apr 2020 11:17:58 +0200
Konrad Hinsen <konrad.hinsen <at> fastmail.net> writes:

> Could we go for "guix guile" and make it option-compatible with plain
> Guile as much as possible? Just an idea, I am not sure it's a good one!
> Guile can already be a pain in a shebang line.

After some exploration, that kind of compatibility doesn't seem worth
the effort.

I will send another patch that implements Simon's proposal:

 - New command "guix run" that extends "guix repl" by an optional
   file argument for running a script.
 - "guix repl" becomes an alias for "guix run" (and could in the
   long run be declared obsolete).

Cheers,
  Konrad.





Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Fri, 03 Apr 2020 09:20:02 GMT) Full text and rfc822 format available.

Message #32 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: 40373 <at> debbugs.gnu.org
Subject: [PATCH] guix: new command "guix run" generalizes "guix repl"
Date: Fri, 03 Apr 2020 11:19:43 +0200
* guix/scripts/run.scm: New file.
* Makefile.am: (MODULES): Add it.
* guix/scripts/repl.scm: Make "guix repl" an alias for "guix run".
* doc/guix.texi: Document "guix run"
---
 Makefile.am           |   1 +
 doc/guix.texi         |  51 ++++++++----
 guix/scripts/repl.scm | 157 +----------------------------------
 guix/scripts/run.scm  | 189 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 229 insertions(+), 169 deletions(-)
 create mode 100644 guix/scripts/run.scm

diff --git a/Makefile.am b/Makefile.am
index 344ecdbc42..db91c4f5da 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -255,6 +255,7 @@ MODULES =					\
   guix/scripts/authenticate.scm			\
   guix/scripts/refresh.scm			\
   guix/scripts/repl.scm				\
+  guix/scripts/run.scm				\
   guix/scripts/describe.scm			\
   guix/scripts/system.scm			\
   guix/scripts/system/search.scm		\
diff --git a/doc/guix.texi b/doc/guix.texi
index 8cb85fe62c..4e4c12866a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -234,7 +234,7 @@ Programming Interface
 * Derivations::                 Low-level interface to package derivations.
 * The Store Monad::             Purely functional interface to the store.
 * G-Expressions::               Manipulating build expressions.
-* Invoking guix repl::          Fiddling with Guix interactively.
+* Invoking guix run::           Programming Guix in Guile
 
 Defining Packages
 
@@ -1154,7 +1154,7 @@ The @command{guix} command must be in the search path on the build
 machines.  You can check whether this is the case by running:
 
 @example
-ssh build-machine guix repl --version
+ssh build-machine guix run --version
 @end example
 
 There is one last thing to do once @file{machines.scm} is in place.  As
@@ -4259,7 +4259,7 @@ revisions in arbitrary ways.
 
 @cindex inferior packages
 Technically, an ``inferior'' is essentially a separate Guix process connected
-to your main Guix process through a REPL (@pxref{Invoking guix repl}).  The
+to your main Guix process through a REPL (@pxref{Invoking guix run}).  The
 @code{(guix inferior)} module allows you to create inferiors and to
 communicate with them.  It also provides a high-level interface to browse and
 manipulate the packages that an inferior provides---@dfn{inferior packages}.
@@ -4318,7 +4318,7 @@ As a side effect, this procedure may build or substitute binaries for
 @deffn {Scheme Procedure} open-inferior @var{directory} @
   [#:command "bin/guix"]
 Open the inferior Guix in @var{directory}, running
-@code{@var{directory}/@var{command} repl} or equivalent.  Return @code{#f} if
+@code{@var{directory}/@var{command} run} or equivalent.  Return @code{#f} if
 the inferior could not be launched.
 @end deffn
 
@@ -5346,7 +5346,8 @@ package definitions.
 * Derivations::                 Low-level interface to package derivations.
 * The Store Monad::             Purely functional interface to the store.
 * G-Expressions::               Manipulating build expressions.
-* Invoking guix repl::          Fiddling with Guix interactively.
+* Invoking guix run::           Programming Guix in Guile
+
 @end menu
 
 @node Package Modules
@@ -8057,25 +8058,43 @@ corresponding to @var{obj} for @var{system}, cross-compiling for
 has an associated gexp compiler, such as a @code{<package>}.
 @end deffn
 
-@node Invoking guix repl
-@section Invoking @command{guix repl}
+@node Invoking guix run
+@section Invoking @command{guix run}
+
+@cindex script, REPL, read-eval-print loop
+The @command{guix run} command makes it easier to program Guix in Guile,
+either by running Guile scripts (@pxref{Running Guile Scripts,,, guile,
+GNU Guile Reference Manual}) or by launching a Guile
+@dfn{read-eval-print loop} (REPL) for interactive programming
+(@pxref{Using Guile Interactively,,, guile, GNU Guile Reference Manual}).
+Compared to just launching the @command{guile}
+command, @command{guix run} guarantees that all the Guix modules and all its
+dependencies are available in the search path.
+
+The general syntax is:
+
+@example
+guix run @var{options} @var{file}
+@end example
+
+When a @var{file} argument is provided, @var{file} is executed as a Guile
+script:
+
+@example
+$ guix run my-script.scm
+@end example
 
-@cindex REPL, read-eval-print loop
-The @command{guix repl} command spawns a Guile @dfn{read-eval-print loop}
-(REPL) for interactive programming (@pxref{Using Guile Interactively,,, guile,
-GNU Guile Reference Manual}).  Compared to just launching the @command{guile}
-command, @command{guix repl} guarantees that all the Guix modules and all its
-dependencies are available in the search path.  You can use it this way:
+Otherwise a Guile REPL is started:
 
 @example
-$ guix repl
+$ guix run
 scheme@@(guile-user)> ,use (gnu packages base)
 scheme@@(guile-user)> coreutils
 $1 = #<package coreutils@@8.29 gnu/packages/base.scm:327 3e28300>
 @end example
 
 @cindex inferiors
-In addition, @command{guix repl} implements a simple machine-readable REPL
+In addition, @command{guix run} implements a simple machine-readable REPL
 protocol for use by @code{(guix inferior)}, a facility to interact with
 @dfn{inferiors}, separate processes running a potentially different revision
 of Guix.
@@ -8114,7 +8133,7 @@ Add @var{directory} to the front of the package module search path
 (@pxref{Package Modules}).
 
 This allows users to define their own packages and make them visible to
-the command-line tool.
+the script or command-line tool.
 
 @item -q
 Inhibit loading of the @file{~/.guile} file.  By default, that
diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm
index ff1f208894..4feca9140a 100644
--- a/guix/scripts/repl.scm
+++ b/guix/scripts/repl.scm
@@ -1,6 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
-;;; Copyright © 2020 Simon Tournier <zimon.toutoune <at> gmail.com>
+;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen <at> fastmail.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -18,159 +17,11 @@
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (guix scripts repl)
-  #:use-module (guix ui)
-  #:use-module (guix scripts)
-  #:use-module (guix repl)
-  #:use-module (srfi srfi-1)
-  #:use-module (srfi srfi-37)
-  #:use-module (ice-9 match)
-  #:use-module (rnrs bytevectors)
-  #:autoload   (system repl repl) (start-repl)
-  #:autoload   (system repl server)
-                  (make-tcp-server-socket make-unix-domain-server-socket)
+  #:use-module (guix scripts run)
   #:export (guix-repl))
 
 ;;; Commentary:
 ;;;
-;;; This command provides a Guile REPL
+;;; This is an alias for "guix run", for backwards compatibility
 
-(define %default-options
-  `((type . guile)))
-
-(define %options
-  (list (option '(#\h "help") #f #f
-                (lambda args
-                  (show-help)
-                  (exit 0)))
-        (option '(#\V "version") #f #f
-                (lambda args
-                  (show-version-and-exit "guix repl")))
-        (option '(#\t "type") #t #f
-                (lambda (opt name arg result)
-                  (alist-cons 'type (string->symbol arg) result)))
-        (option '("listen") #t #f
-                (lambda (opt name arg result)
-                  (alist-cons 'listen arg result)))
-        (option '(#\q) #f #f
-                (lambda (opt name arg result)
-                  (alist-cons 'ignore-dot-guile? #t result)))
-        (option '(#\L "load-path") #t #f
-                (lambda (opt name arg result)
-                  ;; XXX: Imperatively modify the search paths.
-                  (set! %load-path (cons arg %load-path))
-                  (set! %load-compiled-path (cons arg %load-compiled-path))
-                  result))))
-
-
-(define (show-help)
-  (display (G_ "Usage: guix repl [OPTIONS...]
-Start a Guile REPL in the Guix execution environment.\n"))
-  (display (G_ "
-  -t, --type=TYPE        start a REPL of the given TYPE"))
-  (display (G_ "
-      --listen=ENDPOINT  listen to ENDPOINT instead of standard input"))
-  (display (G_ "
-  -q                     inhibit loading of ~/.guile"))
-  (newline)
-  (display (G_ "
-  -L, --load-path=DIR    prepend DIR to the package module search path"))
-  (newline)
-  (display (G_ "
-  -h, --help             display this help and exit"))
-  (display (G_ "
-  -V, --version          display version information and exit"))
-  (newline)
-  (show-bug-report-information))
-
-(define user-module
-  ;; Module where we execute user code.
-  (let ((module (resolve-module '(guix-user) #f #f #:ensure #t)))
-    (beautify-user-module! module)
-    module))
-
-(define (call-with-connection spec thunk)
-  "Dynamically-bind the current input and output ports according to SPEC and
-call THUNK."
-  (if (not spec)
-      (thunk)
-
-      ;; Note: the "PROTO:" prefix in SPEC is here so that we can eventually
-      ;; parse things like "fd:123" in a non-ambiguous way.
-      (match (string-index spec #\:)
-        (#f
-         (leave (G_ "~A: invalid listen specification~%") spec))
-        (index
-         (let ((protocol (string-take spec index))
-               (address  (string-drop spec (+ index 1))))
-           (define socket
-             (match protocol
-               ("tcp"
-                (make-tcp-server-socket #:port (string->number address)))
-               ("unix"
-                (make-unix-domain-server-socket #:path address))
-               (_
-                (leave (G_ "~A: unsupported protocol family~%")
-                       protocol))))
-
-           (listen socket 10)
-           (let loop ()
-             (match (accept socket)
-               ((connection . address)
-                (if (= AF_UNIX (sockaddr:fam address))
-                    (info (G_ "accepted connection~%"))
-                    (info (G_ "accepted connection from ~a~%")
-                          (inet-ntop (sockaddr:fam address)
-                                     (sockaddr:addr address))))
-                (dynamic-wind
-                  (const #t)
-                  (lambda ()
-                    (parameterize ((current-input-port connection)
-                                   (current-output-port connection))
-                      (thunk)))
-                  (lambda ()
-                    (false-if-exception (close-port connection))
-                    (info (G_ "connection closed~%"))))))
-             (loop)))))))
-
-
-(define (guix-repl . args)
-  (define opts
-    ;; Return the list of package names.
-    (args-fold* args %options
-                (lambda (opt name arg result)
-                  (leave (G_ "~A: unrecognized option~%") name))
-                (lambda (arg result)
-                  (leave (G_ "~A: extraneous argument~%") arg))
-                %default-options))
-
-  (define user-config
-    (and=> (getenv "HOME")
-           (lambda (home)
-             (string-append home "/.guile"))))
-
-  (with-error-handling
-    (let ((type (assoc-ref opts 'type)))
-      (call-with-connection (assoc-ref opts 'listen)
-        (lambda ()
-          (case type
-            ((guile)
-             (save-module-excursion
-              (lambda ()
-                (set-current-module user-module)
-                (when (and (not (assoc-ref opts 'ignore-dot-guile?))
-                           user-config
-                           (file-exists? user-config))
-                  (load user-config))
-
-                ;; Do not exit repl on SIGINT.
-                ((@@ (ice-9 top-repl) call-with-sigint)
-                 (lambda ()
-                   (start-repl))))))
-            ((machine)
-             (machine-repl))
-            (else
-             (leave (G_ "~a: unknown type of REPL~%") type))))))))
-
-;; Local Variables:
-;; eval: (put 'call-with-connection 'scheme-indent-function 1)
-;; End:
+(define guix-repl guix-run)
diff --git a/guix/scripts/run.scm b/guix/scripts/run.scm
new file mode 100644
index 0000000000..4f3cfb2c47
--- /dev/null
+++ b/guix/scripts/run.scm
@@ -0,0 +1,189 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2020 Simon Tournier <zimon.toutoune <at> gmail.com>
+;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen <at> fastmail.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix scripts run)
+  #:use-module (guix ui)
+  #:use-module (guix scripts)
+  #:use-module (guix repl)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-37)
+  #:use-module (ice-9 match)
+  #:use-module (rnrs bytevectors)
+  #:autoload   (system repl repl) (start-repl)
+  #:autoload   (system repl server)
+                  (make-tcp-server-socket make-unix-domain-server-socket)
+  #:export (guix-run))
+
+;;; Commentary:
+;;;
+;;; This command provides a Guile script runner and REPL in an environment
+;;; that contains all the modules comprising Guix.
+
+(define %default-options
+  `((type . guile)))
+
+(define %options
+  (list (option '(#\h "help") #f #f
+                (lambda args
+                  (show-help)
+                  (exit 0)))
+        (option '(#\V "version") #f #f
+                (lambda args
+                  (show-version-and-exit "guix repl")))
+        (option '(#\t "type") #t #f
+                (lambda (opt name arg result)
+                  (alist-cons 'type (string->symbol arg) result)))
+        (option '("listen") #t #f
+                (lambda (opt name arg result)
+                  (alist-cons 'listen arg result)))
+        (option '(#\q) #f #f
+                (lambda (opt name arg result)
+                  (alist-cons 'ignore-dot-guile? #t result)))
+        (option '(#\L "load-path") #t #f
+                (lambda (opt name arg result)
+                  ;; XXX: Imperatively modify the search paths.
+                  (set! %load-path (cons arg %load-path))
+                  (set! %load-compiled-path (cons arg %load-compiled-path))
+                  result))))
+
+
+(define (show-help)
+  (display (G_ "Usage: guix run [OPTIONS...] [FILE]
+Run FILE as a Guile script, or start a Guile REPL, in the Guix
+execution environment.\n"))
+  (display (G_ "
+  -t, --type=TYPE        start a REPL of the given TYPE"))
+  (display (G_ "
+      --listen=ENDPOINT  listen to ENDPOINT instead of standard input"))
+  (display (G_ "
+  -q                     inhibit loading of ~/.guile"))
+  (newline)
+  (display (G_ "
+  -L, --load-path=DIR    prepend DIR to the package module search path"))
+  (newline)
+  (display (G_ "
+  -h, --help             display this help and exit"))
+  (display (G_ "
+  -V, --version          display version information and exit"))
+  (newline)
+  (show-bug-report-information))
+
+(define user-module
+  ;; Module where we execute user code.
+  (let ((module (resolve-module '(guix-user) #f #f #:ensure #t)))
+    (beautify-user-module! module)
+    module))
+
+(define (call-with-connection spec thunk)
+  "Dynamically-bind the current input and output ports according to SPEC and
+call THUNK."
+  (if (not spec)
+      (thunk)
+
+      ;; Note: the "PROTO:" prefix in SPEC is here so that we can eventually
+      ;; parse things like "fd:123" in a non-ambiguous way.
+      (match (string-index spec #\:)
+        (#f
+         (leave (G_ "~A: invalid listen specification~%") spec))
+        (index
+         (let ((protocol (string-take spec index))
+               (address  (string-drop spec (+ index 1))))
+           (define socket
+             (match protocol
+               ("tcp"
+                (make-tcp-server-socket #:port (string->number address)))
+               ("unix"
+                (make-unix-domain-server-socket #:path address))
+               (_
+                (leave (G_ "~A: unsupported protocol family~%")
+                       protocol))))
+
+           (listen socket 10)
+           (let loop ()
+             (match (accept socket)
+               ((connection . address)
+                (if (= AF_UNIX (sockaddr:fam address))
+                    (info (G_ "accepted connection~%"))
+                    (info (G_ "accepted connection from ~a~%")
+                          (inet-ntop (sockaddr:fam address)
+                                     (sockaddr:addr address))))
+                (dynamic-wind
+                  (const #t)
+                  (lambda ()
+                    (parameterize ((current-input-port connection)
+                                   (current-output-port connection))
+                      (thunk)))
+                  (lambda ()
+                    (false-if-exception (close-port connection))
+                    (info (G_ "connection closed~%"))))))
+             (loop)))))))
+
+
+(define (guix-run . args)
+  (define opts
+    (args-fold* args %options
+                (lambda (opt name arg result)
+                  (leave (G_ "~A: unrecognized option~%") name))
+                (lambda (arg result)
+                  (when (assq 'argument result)
+                    (leave (G_ "~A: extraneous argument~%") arg))
+                  (alist-cons 'argument arg result))
+                %default-options))
+
+  (define user-config
+    (and=> (getenv "HOME")
+           (lambda (home)
+             (string-append home "/.guile"))))
+
+  (define (set-user-module)
+    (set-current-module user-module)
+    (when (and (not (assoc-ref opts 'ignore-dot-guile?))
+               user-config
+               (file-exists? user-config))
+      (load user-config)))
+  
+  (with-error-handling
+    (let ((script (assoc-ref opts 'argument))
+          (type (assoc-ref opts 'type)))
+      (if script
+          (save-module-excursion
+           (lambda ()
+             (set-user-module)
+             (load script)))
+          (call-with-connection (assoc-ref opts 'listen)
+            (lambda ()
+              (case type
+                ((guile)
+                 (save-module-excursion
+                  (lambda ()
+                    (set-user-module)
+                    ;; Do not exit repl on SIGINT.
+                    ((@@ (ice-9 top-repl) call-with-sigint)
+                     (lambda ()
+                       (start-repl))))))
+                ((machine)
+                 (machine-repl))
+                (else
+                 (leave (G_ "~a: unknown type of REPL~%") type))))))))
+
+  ;; Local Variables:
+  ;; eval: (put 'call-with-connection 'scheme-indent-function 1)
+  ;; End:
+  )
-- 
2.26.0




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Fri, 03 Apr 2020 09:49:02 GMT) Full text and rfc822 format available.

Message #35 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: 40373 <at> debbugs.gnu.org, zimoun <zimon.toutoune <at> gmail.com>
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Fri, 03 Apr 2020 11:48:11 +0200
Hi Konrad,

Konrad Hinsen <konrad.hinsen <at> fastmail.net> skribis:

> Konrad Hinsen <konrad.hinsen <at> fastmail.net> writes:
>
>> Could we go for "guix guile" and make it option-compatible with plain
>> Guile as much as possible? Just an idea, I am not sure it's a good one!
>> Guile can already be a pain in a shebang line.
>
> After some exploration, that kind of compatibility doesn't seem worth
> the effort.
>
> I will send another patch that implements Simon's proposal:
>
>  - New command "guix run" that extends "guix repl" by an optional
>    file argument for running a script.

“guix run” was sort of reserved for something else:

  https://lists.gnu.org/archive/html/help-guix/2018-01/msg00118.html

The idea is still floating around so perhaps we should keep that name.

>  - "guix repl" becomes an alias for "guix run" (and could in the
>    long run be declared obsolete).

I’m worried about a possible increase of the deprecation rate.  I
understand the rationale, I think it makes sense, but still, I’m not
sure we need to deprecate “guix repl” already.

In fact, since it’s used by inferiors, we must pay extra attention to
keep it as-is as much as possible or we’ll make communication between
old and new Guixes difficult.

Thoughts?

Thanks,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Fri, 03 Apr 2020 09:52:02 GMT) Full text and rfc822 format available.

Message #38 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Fri, 03 Apr 2020 11:51:42 +0200
Hello,

Konrad Hinsen <konrad.hinsen <at> fastmail.net> skribis:

> The other is that I am in tutorial-driven development mode: I need "guix
> run-script" in order to be able to insert my own scripts (for analyzing
> dependencies) into a Guix tutorial for an upcoming MOOC. So I need to
> make sure that people can run my scripts easily, but also that they
> understand what they are doing. A command that does something else than
> its name suggests, with a similarity that is only visible to experts,
> is no good for use in a tutorial.

I see.  (I have to ponder this a bit more.)

> I am of course aware that much of the code in "run-script" is the same
> as in "repl", which is not good.

Yes, we can probably factorize a bit.  We must make sure ‘-q’ is not
implemented by this command; ‘-t’ is also useless.

> But I'd rather think about a better framework for code sharing among
> Guix scripts than about pushing too much semantic differences into
> obscure options. An example would be reusable "option clusters", such
> as "options for Guile" or "options for channels".

We do have that with ‘%standard-build-options’, for instance, although
not as nicely-structured as we’d like (in general, I’d prefer to have a
GNU argp-style command-line API than what we have).

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Tue, 07 Apr 2020 09:11:01 GMT) Full text and rfc822 format available.

Message #41 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Tue, 07 Apr 2020 11:10:40 +0200
Hi Ludo,

>> I am of course aware that much of the code in "run-script" is the same
>> as in "repl", which is not good.
>
> Yes, we can probably factorize a bit.  We must make sure ‘-q’ is not
> implemented by this command; ‘-t’ is also useless.

Right.

> We do have that with ‘%standard-build-options’, for instance, although
> not as nicely-structured as we’d like (in general, I’d prefer to have a
> GNU argp-style command-line API than what we have).

It would also be nice to share the documentation for these options among
different scripts. That's actually more lines of code than the code
itself.

More generally, it would be nice to decouple implementation decisions
from user interface decisions. Git provides a nice example of what
happens when user interface design follows ease of implementation
criteria for a while. It's probably the most hated essential piece of
software by now.

From a user interface point of view, it is preferable to have many
commands with clear names, rather than few commands overloaded with
multiple functions selected by cryptic options.

Cheers,
  Konrad




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Tue, 07 Apr 2020 10:37:02 GMT) Full text and rfc822 format available.

Message #44 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Tue, 07 Apr 2020 12:36:41 +0200
Hello,

Konrad Hinsen <konrad.hinsen <at> fastmail.net> skribis:

> From a user interface point of view, it is preferable to have many
> commands with clear names, rather than few commands overloaded with
> multiple functions selected by cryptic options.

I agree overall, though it’s not black and white: the benefit of having
separate commands weakens as they proliferate.  A new command may be
more difficult to discover than an option to an existing command.

But anyway, let’s see how we can get ‘run-script’ in!  :-)

Thanks,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Fri, 17 Apr 2020 11:22:01 GMT) Full text and rfc822 format available.

Message #47 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: Konrad Hinsen <konrad.hinsen <at> fastmail.net>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Fri, 17 Apr 2020 13:21:32 +0200
Dear,

Naming is hard. :-)

Why not simply add an option to "guix repl"?
For example "--batch", mimicking  "emacs --batch".
Or "--script".

Or "guix repl <file>" just run the <file> as the proposed "guix run-script"?


I do not have the feeling that adding a new subcommand is mandatory.
But running a script using the Guix modules is really useful, I always
complain to myself of this lacking feature. :-)


Cheers,
simon




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 23 Apr 2020 10:14:02 GMT) Full text and rfc822 format available.

Message #50 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: zimoun <zimon.toutoune <at> gmail.com>, Ludovic Courtès
 <ludo <at> gnu.org>
Cc: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 23 Apr 2020 12:12:59 +0200
Hi Simon,

> Why not simply add an option to "guix repl"?
> For example "--batch", mimicking  "emacs --batch".
> Or "--script".

Do you have a suggestion for explaining such a command to someone who
want to run a script bu (1) doesn't know what a REPL is, (2) doesn't
need to know what a REPL is, (3) would be mystified by the behavior
resulting from forgetting the –script argument?

I agree of course that naming is hard, but it is also important.  Git
should be a sufficient demonstration of what happens when you design
command-line interfaces by a sequence of cumulative least-effort
decisions.

Cheers,
  Konrad




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 23 Apr 2020 14:42:01 GMT) Full text and rfc822 format available.

Message #53 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 23 Apr 2020 16:41:03 +0200
Hi Konrad,

On Thu, 23 Apr 2020 at 12:13, Konrad Hinsen <konrad.hinsen <at> fastmail.net> wrote:

> > Why not simply add an option to "guix repl"?
> > For example "--batch", mimicking  "emacs --batch".
> > Or "--script".
>
> Do you have a suggestion for explaining such a command to someone who
> want to run a script bu (1) doesn't know what a REPL is, (2) doesn't
> need to know what a REPL is, (3) would be mystified by the behavior
> resulting from forgetting the –script argument?

If I understand well
     guix run-script file1 file2
is becoming:
    guix repl --script=file1,file2,...
right?

Well, I would say that

--8<---------------cut here---------------start------------->8---
the keyword "repl" stand for Read-Eval-Print-Loop
therefore the command will:
  - read the script file1,
  - eval it,
  - print the results if they are,
  - and finally loop if there is more than one script file.
--8<---------------cut here---------------end--------------->8---

this fills the condition (1) and (2); at least to me. ;-)


I agree that forgetting the argument '--script' could mystified the learner.

But applying the same principles, the command
    guix environment --ad-hoc python -- python
could mystified the learner too, if for example they forgets --ad-hoc
or '-- python'.

Well, this kind of disconcerting "mistakes" is part of the learning
process, IMHO.
Others call that "discoverability". ;-)


> I agree of course that naming is hard, but it is also important.  Git
> should be a sufficient demonstration of what happens when you design
> command-line interfaces by a sequence of cumulative least-effort
> decisions.

I agree.
And I still have in my stack how to propose another CLI naming as we
discussed earlier, e.g.,
    environment, package, etc.
reorganized into
  profile, install, search, etc.


Cheers,
sion




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Wed, 29 Apr 2020 16:05:01 GMT) Full text and rfc822 format available.

Message #56 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Wed, 29 Apr 2020 18:04:40 +0200
Hi Simon,

> If I understand well
>      guix run-script file1 file2
> is becoming:
>     guix repl --script=file1,file2,...
> right?
>
> Well, I would say that
>
> --8<---------------cut here---------------start------------->8---
> the keyword "repl" stand for Read-Eval-Print-Loop
> therefore the command will:
>   - read the script file1,
>   - eval it,
>   - print the results if they are,
>   - and finally loop if there is more than one script file.
> --8<---------------cut here---------------end--------------->8---

That's very clever! The weak spot is the P, as script evaluation does
not print anything. We could make it print the script's return code ;-)

> But applying the same principles, the command
>     guix environment --ad-hoc python -- python
> could mystified the learner too, if for example they forgets --ad-hoc
> or '-- python'.

Indeed. I never said that existing Guix commands are perfect ;-)
In fact, I remember some debate about precisely the case of "guix
environment".

> And I still have in my stack how to propose another CLI naming as we
> discussed earlier, e.g.,
>     environment, package, etc.
> reorganized into
>   profile, install, search, etc.

The CLI as an eternal construction site ;-)

Cheers,
  Konrad




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 30 Apr 2020 12:43:01 GMT) Full text and rfc822 format available.

Message #59 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 30 Apr 2020 14:42:33 +0200
Hi Konrad,

On Wed, 29 Apr 2020 at 18:04, Konrad Hinsen <konrad.hinsen <at> fastmail.net> wrote:

> That's very clever! The weak spot is the P, as script evaluation does
> not print anything. We could make it print the script's return code ;-)

Hum? The usual REPL neither. :-)
Quoting Wikipedia: "print function takes the result yielded by eval"
but from my understanding 'eval' does not always yield a "printable"
result, e.g., "(define foo 42)".


Cheers,
simon




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Mon, 04 May 2020 13:56:01 GMT) Full text and rfc822 format available.

Message #62 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Mon, 04 May 2020 15:54:59 +0200
Hi Simon,

>> That's very clever! The weak spot is the P, as script evaluation does
>> not print anything. We could make it print the script's return code ;-)
>
> Hum? The usual REPL neither. :-)

You mean... they have been LYING to us all the time... about the REPL?

> Quoting Wikipedia: "print function takes the result yielded by eval"
> but from my understanding 'eval' does not always yield a "printable"
> result, e.g., "(define foo 42)".

True, not always. But for scripts it's never. We have to find some nice
three-valued logic rhetoric that applies to all situations ;-)

Command line:
  - read an expression,
  - eval it,
  - print the result of the evaluation (if any),
  - and finally loop to process the next expression

Scripts:
  - read the script file1,
  - eval it,
  - print the textual output of the script (if any),
  - and finally loop if there is more than one script file.

That makes "print" look optional in both cases.

Cheers,
  Konrad.




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Mon, 04 May 2020 17:49:02 GMT) Full text and rfc822 format available.

Message #65 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Mon, 4 May 2020 19:48:19 +0200
Hi Konrad,

On Mon, 4 May 2020 at 15:55, Konrad Hinsen <konrad.hinsen <at> fastmail.net> wrote:

> True, not always. But for scripts it's never. We have to find some nice
> three-valued logic rhetoric that applies to all situations ;-)
>
> Command line:
>   - read an expression,
>   - eval it,
>   - print the result of the evaluation (if any),
>   - and finally loop to process the next expression
>
> Scripts:
>   - read the script file1,
>   - eval it,
>   - print the textual output of the script (if any),
>   - and finally loop if there is more than one script file.
>
> That makes "print" look optional in both cases.

It is how I personally understand all that. :-)
So that's why I proposed "guix repl --script" (in short '-s') ;-)

In this frame of "guix repl", the future additions/evolution could be:

  --eval,-e for evaluating one expression just after the script is loaded
  --debug for starting the "debugging" VM engine (personally never
used with Guile)
  --language for switching to WISP (optimistic evolution of GWL :-))
  --use-srfi for loading SRFI modules

So it ends up with this kind of command-line:

  guix repl -L /path/to/stuff --use-srfi=9
  guix repl -L /path/to/custom -s file.scm
  guix repl --language=wisp --script file.wsp
  guix repl -s file.scm -e '(package-name foo)'

Well, 'repl' meaning "use the interpreter in the context of Guix".
Is 'repl' enough meaningful for these use cases? Personally, I think so. :-)


All the best,
simon




Information forwarded to guix-patches <at> gnu.org:
bug#40373; Package guix-patches. (Thu, 14 May 2020 09:30:02 GMT) Full text and rfc822 format available.

Message #68 received at 40373 <at> debbugs.gnu.org (full text, mbox):

From: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
To: 40373 <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 14 May 2020 11:29:36 +0200
Hi everyone,

Since this proposition does not seem to be going anywhere, I have
submitted an alternative patch as bug#41253 which simply adds script
execution to "guix repl", with no changes to the existing behavior, nor
any new command. For my tutorial, I will use shell scripts that hide the
guix command line from view, so that I do not have to explain it.

This bug can thus be closed, and I'd have done it already if I knew
how. I couldn't find any instructions.

Cheers,
  Konrad.




Reply sent to zimoun <zimon.toutoune <at> gmail.com>:
You have taken responsibility. (Thu, 14 May 2020 09:46:01 GMT) Full text and rfc822 format available.

Notification sent to Konrad Hinsen <konrad.hinsen <at> fastmail.net>:
bug acknowledged by developer. (Thu, 14 May 2020 09:46:01 GMT) Full text and rfc822 format available.

Message #73 received at 40373-done <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: Konrad Hinsen <konrad.hinsen <at> fastmail.net>
Cc: 40373-done <at> debbugs.gnu.org
Subject: Re: [bug#40373] [PATCH] guix: new command "guix run-script"
Date: Thu, 14 May 2020 11:44:53 +0200
Hi Konrad,

On Thu, 14 May 2020 at 11:30, Konrad Hinsen <konrad.hinsen <at> fastmail.net> wrote:

> Since this proposition does not seem to be going anywhere, I have
> submitted an alternative patch as bug#41253 which simply adds script
> execution to "guix repl", with no changes to the existing behavior, nor
> any new command. For my tutorial, I will use shell scripts that hide the
> guix command line from view, so that I do not have to explain it.

Cool!

> This bug can thus be closed, and I'd have done it already if I knew
> how. I couldn't find any instructions.

Two ways:
 - answer to 40373-done <at> debbugs.gnu.org; as it is done here.
 - send to controls <at> debbugs.gnu.org with the body:
       close 30373
       thanks

https://debbugs.gnu.org/server-control.html

Cheers,
simon




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 11 Jun 2020 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 318 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.