diff mbox series

[bug#70839,2/3] channels: Add `read-channels-file' procedure.

Message ID 06234d6dbf04c97da49ecadb8f8d139bf1fe1536.1715208954.git.~@wolfsden.cz
State New
Headers show
Series Minor changes to `channels' field and related doc. | expand

Commit Message

Tomas Volf May 8, 2024, 11:13 p.m. UTC
This commit moves non-exported local procedure from (guix pull) in order to
provide a single, canonical way to read a file produced by `guix describe
--format=channels'.

* guix/channels.scm (read-channels-file): New procedure.
(define-module): Export it.
* guix/scripts/pull.scm (channel-list): Use it.

Change-Id: I147fdf3cb177114f4607209de2299f46761b64be
---
 guix/channels.scm     | 14 +++++++++++++-
 guix/scripts/pull.scm | 12 +++---------
 2 files changed, 16 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/guix/channels.scm b/guix/channels.scm
index 51024dcad4..38d5c8c325 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -37,6 +37,7 @@  (define-module (guix channels)
   #:autoload   (guix git-authenticate) (authenticate-repository)
   #:autoload   (guix openpgp) (openpgp-public-key-fingerprint
                                openpgp-format-fingerprint)
+  #:autoload   (guix ui) (load* make-user-module)
   #:use-module (guix base16)
   #:use-module (guix records)
   #:use-module (guix gexp)
@@ -111,7 +112,9 @@  (define-module (guix channels)
             channel-news-entry-title
             channel-news-entry-body
 
-            channel-news-for-commit))
+            channel-news-for-commit
+
+            read-channels-file))
 
 ;;; Commentary:
 ;;;
@@ -1086,6 +1089,15 @@  (define* (channel->code channel #:key (include-introduction? #t))
                                  intro))))))
             '()))))
 
+(define (read-channels-file file)
+  "Return channel list read from FILE.
+
+The file shall have format produced by `guix describe --format=channels'."
+  (let ((result (load* file (make-user-module '((guix channels))))))
+    (if (and (list? result) (every channel? result))
+        result
+        (leave (G_ "'~a' did not return a list of channels~%") file))))
+
 
 ;;;
 ;;; News.
diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm
index 58d3cd7e83..7240b2f25e 100644
--- a/guix/scripts/pull.scm
+++ b/guix/scripts/pull.scm
@@ -750,21 +750,15 @@  (define (channel-list opts)
   (define global-file
     (string-append %sysconfdir "/guix/channels.scm"))
 
-  (define (load-channels file)
-    (let ((result (load* file (make-user-module '((guix channels))))))
-      (if (and (list? result) (every channel? result))
-          result
-          (leave (G_ "'~a' did not return a list of channels~%") file))))
-
   (define channels
     (cond (file
-           (load-channels file))
+           (read-channels-file file))
           ((and (not ignore-channel-files?)
                 (file-exists? default-file))
-           (load-channels default-file))
+           (read-channels-file default-file))
           ((and (not ignore-channel-files?)
                 (file-exists? global-file))
-           (load-channels global-file))
+           (read-channels-file global-file))
           (else
            %default-channels)))