From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WC2oIgwNvV7kYAAA0tVLHw (envelope-from ) for ; Thu, 14 May 2020 09:19:08 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6PzkHAwNvV6MZAAAbx9fmQ (envelope-from ) for ; Thu, 14 May 2020 09:19:08 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2DA68940D8A for ; Thu, 14 May 2020 09:19:05 +0000 (UTC) Received: from localhost ([::1]:44652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZA1C-0006Dj-A0 for larch@yhetil.org; Thu, 14 May 2020 05:19:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZA19-0006Db-3e for guix-patches@gnu.org; Thu, 14 May 2020 05:19:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:48697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jZA18-0003cf-Qo for guix-patches@gnu.org; Thu, 14 May 2020 05:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jZA18-0007tC-Kz for guix-patches@gnu.org; Thu, 14 May 2020 05:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41253] [PATCH] guix: add script execution to "guix repl" Resent-From: Konrad Hinsen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 14 May 2020 09:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41253 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 41253@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.158944793130298 (code B ref -1); Thu, 14 May 2020 09:19:02 +0000 Received: (at submit) by debbugs.gnu.org; 14 May 2020 09:18:51 +0000 Received: from localhost ([127.0.0.1]:60243 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jZA0x-0007sc-08 for submit@debbugs.gnu.org; Thu, 14 May 2020 05:18:51 -0400 Received: from lists.gnu.org ([209.51.188.17]:43720) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jZA0v-0007sV-Uk for submit@debbugs.gnu.org; Thu, 14 May 2020 05:18:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZA0v-0006C2-OR for guix-patches@gnu.org; Thu, 14 May 2020 05:18:49 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:41081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZA0u-0003Y3-HL for guix-patches@gnu.org; Thu, 14 May 2020 05:18:49 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 19C435C0152; Thu, 14 May 2020 05:18:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 14 May 2020 05:18:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.net; h= from:to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=fm3; bh=7bN7BFmcPgx7J4JntQjkZv5iBB uMhySYS7Cws3cE32A=; b=pDJa3lLmoSPwf+G0joeidShvZUHUGBKobWDcnny1j/ q6Ycz8ZD6R4dJkFxHgtzCKK5aRjJJdQiaZW3Ag4k7KZpEp+BZ4FkYkkHHF/cS917 RSu40nN7AIdjzqlOZ4C9aKtf9U03QEsJ5pcM5ni5F2OxtFuqvMYRLRCtS5CV8oNx 3a293NbneYnU9qL7pHY0L/4ytvf9c1TSmzntgSzc986nqWfsjuXClgCWk+tXNm/X Vl324Un0+Wgd7JBPPmrolNS8Mg1ktOspZDMIgjvpn9pecI5T/KMkl+Sh2VOIUlCQ erIRXFg1yvzZbm4SOPOb/otfNA4YL7DXtw+MYFBMkq5Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=7bN7BF mcPgx7J4JntQjkZv5iBBuMhySYS7Cws3cE32A=; b=GUI+M3v/7xzQhZay2i0RBG GqiNdGZ7VMYGcS8eeOaga37BgSmDwuX440JfHCQY9fz20OfK8yCb9DYLT8KDWjCm VwR1iAkPzVz9BHA2bh1Zvhq4Rg4zjfMLZn9ivnQPNQSytpY2poJkGYqTg6n2CV2Y GXjK1AEZysL62Ye5wsthOYNOG824sCVDXLWUEmcdXKMIVRLEyJFngMT5iNzHk4Ip +3BRNIjWKb3XsbJC2sWLxD3vi0cqq4k3Mnl58kYCkEnQun4j6cwDb2MtFZWhYgFA cL551NqYRVmCwBryVcyeRDW+02rZYyGF2emYKZVlI9TlKmFogbqRM134DKvFvo0A == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrleeigdduvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkfggtgfgsehtqhertddttd ejnecuhfhrohhmpefmohhnrhgrugcujfhinhhsvghnuceokhhonhhrrggurdhhihhnshgv nhesfhgrshhtmhgrihhlrdhnvghtqeenucggtffrrghtthgvrhhnpefghfeuffehhfeuge fhvdeugfekfeegudeltdehveehkeekfefftdehgeejjedufeenucfkphepledvrdduieel rddujeefrddvvdehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepkhhonhhrrggurdhhihhnshgvnhesfhgrshhtmhgrihhlrdhnvght X-ME-Proxy: Received: from khs-macbook.home (lfbn-idf2-1-1364-225.w92-169.abo.wanadoo.fr [92.169.173.225]) by mail.messagingengine.com (Postfix) with ESMTPA id 6E8AD3060BB5; Thu, 14 May 2020 05:18:45 -0400 (EDT) From: Konrad Hinsen Date: Thu, 14 May 2020 11:18:43 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=66.111.4.25; envelope-from=konrad.hinsen@fastmail.net; helo=out1-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/14 05:18:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: 0.4 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -2.6 (--) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 X-Spam-Score: 1.59 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=fastmail.net header.s=fm3 header.b=pDJa3lLm; dkim=fail (body hash did not verify) header.d=messagingengine.com header.s=fm2 header.b=GUI+M3v/; dmarc=fail reason="SPF not aligned (relaxed)" header.from=fastmail.net (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Scan-Result: default: False [1.59 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.5393031243397]; MX_INVALID(1.00)[cached]; DWL_DNSWL_BLOCKED(0.00)[209.51.188.17:from]; R_DKIM_REJECT(1.00)[fastmail.net:s=fm3,messagingengine.com:s=fm2]; R_SPF_ALLOW(-0.20)[+ip4:209.51.188.0/24:c]; FREEMAIL_FROM(0.00)[fastmail.net]; RCVD_COUNT_TWELVE(0.00)[12]; TO_DN_NONE(0.00)[]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.05), country: US(-0.00), ip: 209.51.188.17(-0.54)]; DKIM_TRACE(0.00)[fastmail.net:-,messagingengine.com:-]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:209.51.188.0/24, country:US]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[konrad.hinsen@fastmail.net,guix-patches-bounces@gnu.org]; ARC_NA(0.00)[]; URIBL_BLOCKED(0.00)[fastmail.net:email,gnu.org:email]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; DNSWL_BLOCKED(0.00)[209.51.188.17:from]; FORGED_SENDER_MAILLIST(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[fastmail.net : SPF not aligned (relaxed),none] X-TUID: PyBukLO4SOph * guix/scripts/repl.scm: Add filename options for script execution. * doc/guix.texi: Document script execution by "guix repl" --- doc/guix.texi | 38 +++++++++++++++----- guix/scripts/repl.scm | 80 ++++++++++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 40 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index d6fbd85fde..68f1a8bba3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -238,7 +238,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 repl:: Programming Guix in Guile =20 Defining Packages =20 @@ -5415,7 +5415,7 @@ 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 repl:: Programming Guix in Guile @end menu =20 @node Package Modules @@ -8134,12 +8134,31 @@ has an associated gexp compiler, such as a @code{}. @node Invoking guix repl @section Invoking @command{guix repl} =20 -@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,,, gu= ile, -GNU Guile Reference Manual}). Compared to just launching the @command{gui= le} +@cindex REPL, read-eval-print loop, script +The @command{guix repl} command makes it easier to program Guix in Guile +by launching a Guile @dfn{read-eval-print loop} (REPL) for interactive +programming (@pxref{Using Guile Interactively,,, guile, +GNU Guile Reference Manual}), or by running Guile scripts +(@pxref{Running Guile Scripts,,, 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: +dependencies are available in the search path. + +The general syntax is: + +@example +guix repl @var{options} @var{files} +@end example + +When at least one @var{files} argument is provided, @var{files} are +executed as Guile scripts in the given order: + +@example +$ guix repl my-script.scm +@end example + +Otherwise a Guile REPL is started: =20 @example $ guix repl @@ -8188,11 +8207,12 @@ Add @var{directory} to the front of the package mod= ule search path (@pxref{Package Modules}). =20 This allows users to define their own packages and make them visible to -the command-line tool. +the scripts or REPL. =20 @item -q Inhibit loading of the @file{~/.guile} file. By default, that -configuration file is loaded when spawning a @code{guile} REPL. +configuration file is loaded when executing scripts or spawning +a @code{guile} REPL. @end table =20 @c ********************************************************************* diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm index ff1f208894..f4cb744bbd 100644 --- a/guix/scripts/repl.scm +++ b/guix/scripts/repl.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2018, 2019, 2020 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2020 Simon Tournier +;;; Copyright =C2=A9 2020 Konrad Hinsen ;;; ;;; This file is part of GNU Guix. ;;; @@ -32,10 +33,12 @@ =20 ;;; Commentary: ;;; -;;; This command provides a Guile REPL +;;; This command provides a Guile script runner and REPL in an environment +;;; that contains all the modules comprising Guix. =20 (define %default-options - `((type . guile))) + `((scripts . ()) + (type . guile))) =20 (define %options (list (option '(#\h "help") #f #f @@ -63,8 +66,9 @@ =20 =20 (define (show-help) - (display (G_ "Usage: guix repl [OPTIONS...] -Start a Guile REPL in the Guix execution environment.\n")) + (display (G_ "Usage: guix repl [OPTIONS...] [FILES...] +In the Guix execution environment, run FILES as Guile scripts, +or start a Guile REPL if no FILES are given,\n")) (display (G_ " -t, --type=3DTYPE start a REPL of the given TYPE")) (display (G_ " @@ -135,12 +139,13 @@ call THUNK." (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)) + (alist-cons 'scripts + (cons arg (cdr (assq 'scripts result))) + result)) %default-options)) =20 (define user-config @@ -148,29 +153,42 @@ call THUNK." (lambda (home) (string-append home "/.guile")))) =20 + (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 ((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: + (let ((scripts (reverse (assoc-ref opts 'scripts)))) + + (for-each (lambda (script) + (save-module-excursion + (lambda () + (set-user-module) + (load script)))) + scripts) + + (when (null? scripts) + (let ((type (assoc-ref opts 'type))) + (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: + ) --=20 2.26.2