import: egg: Allow imports of a specific version.

* guix/import/egg.scm (eggs-repository): Change URL.
(egg-metadata): Accept optional #:version keyword argument.
(egg->guix-package): Accept ‘version’ argument.
(egg-recursive-import): Add ‘version’ argument and honor it.
* guix/scripts/import/egg.scm (guix-import-egg): Parse a specification instead
of just a package name.
* doc/guix.texi (Invoking guix import): Document it.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Xinglu Chen 2021-11-01 11:55:26 +01:00 committed by Ludovic Courtès
parent 2f665d4309
commit b999c80c2e
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
3 changed files with 46 additions and 33 deletions

View file

@ -12166,7 +12166,7 @@ coexist.
@cindex egg @cindex egg
Import metadata for @uref{https://wiki.call-cc.org/eggs, CHICKEN eggs}. Import metadata for @uref{https://wiki.call-cc.org/eggs, CHICKEN eggs}.
The information is taken from @file{PACKAGE.egg} files found in the The information is taken from @file{PACKAGE.egg} files found in the
@uref{git://code.call-cc.org/eggs-5-latest, eggs-5-latest} Git @uref{git://code.call-cc.org/eggs-5-all, eggs-5-all} Git
repository. However, it does not provide all the information that we repository. However, it does not provide all the information that we
need, there is no ``description'' field, and the licenses used are not need, there is no ``description'' field, and the licenses used are not
always precise (BSD is often used instead of BSD-N). always precise (BSD is often used instead of BSD-N).
@ -12175,6 +12175,12 @@ always precise (BSD is often used instead of BSD-N).
guix import egg sourcehut guix import egg sourcehut
@end example @end example
You can also ask for a specific version:
@example
guix import egg arrays@@1.0
@end example
Additional options include: Additional options include:
@table @code @table @code
@item --recursive @item --recursive

View file

@ -51,10 +51,10 @@ (define-module (guix import egg)
;;; ;;;
;;; The following happens under the hood: ;;; The following happens under the hood:
;;; ;;;
;;; * <git://code.call-cc.org/eggs-5-latest> is a Git repository that contains ;;; * <git://code.call-cc.org/eggs-5-all> is a Git repository that contains
;;; the latest version of all CHICKEN eggs. We look clone this repository ;;; all versions of all CHICKEN eggs. We look clone this repository and, by
;;; and retrieve the latest version number, and the PACKAGE.egg file, which ;;; default, retrieve the latest version number, and the PACKAGE.egg file,
;;; contains a list of lists containing metadata about the egg. ;;; which contains a list of lists containing metadata about the egg.
;;; ;;;
;;; * All the eggs are stored as tarballs at ;;; * All the eggs are stored as tarballs at
;;; <https://code.call-cc.org/egg-tarballs/5>, so we grab the tarball for ;;; <https://code.call-cc.org/egg-tarballs/5>, so we grab the tarball for
@ -96,7 +96,7 @@ (define (egg-name->guix-name name)
(define (eggs-repository) (define (eggs-repository)
"Update or fetch the latest version of the eggs repository and return the path "Update or fetch the latest version of the eggs repository and return the path
to the repository." to the repository."
(let* ((url "git://code.call-cc.org/eggs-5-latest") (let* ((url "git://code.call-cc.org/eggs-5-all")
(directory commit _ (update-cached-checkout url))) (directory commit _ (update-cached-checkout url)))
directory)) directory))
@ -112,12 +112,13 @@ (define (find-latest-version name)
(last directory) (last directory)
#f))) #f)))
(define* (egg-metadata name #:optional file) (define* (egg-metadata name #:key (version #f) (file #f))
"Return the package metadata file for the egg NAME, or if FILE is specified, "Return the package metadata file for the egg NAME at version VERSION, or if
return the package metadata in FILE." FILE is specified, return the package metadata in FILE."
(call-with-input-file (or file (call-with-input-file (or file
(string-append (egg-directory name) "/" (string-append (egg-directory name) "/"
(find-latest-version name) (or version
(find-latest-version name))
"/" name ".egg")) "/" name ".egg"))
read)) read))
@ -173,10 +174,11 @@ (define string->license
;;; Egg importer. ;;; Egg importer.
;;; ;;;
(define* (egg->guix-package name #:key (file #f) (source #f)) (define* (egg->guix-package name version #:key (file #f) (source #f))
"Import a CHICKEN egg called NAME from either the given .egg FILE, or from "Import a CHICKEN egg called NAME from either the given .egg FILE, or from the
the latest NAME metadata downloaded from the official repository if FILE is #f. latest NAME metadata downloaded from the official repository if FILE is #f.
Return a <package> record or #f on failure. Return a <package> record or #f on failure. If VERSION is specified, import
the particular version from the egg repository.
SOURCE is a ``file-like'' object containing the source code corresponding to SOURCE is a ``file-like'' object containing the source code corresponding to
the egg. If SOURCE is not specified, the latest tarball for egg NAME will be the egg. If SOURCE is not specified, the latest tarball for egg NAME will be
@ -186,8 +188,8 @@ (define* (egg->guix-package name #:key (file #f) (source #f))
locally. Note that if FILE and SOURCE are specified, recursive import will locally. Note that if FILE and SOURCE are specified, recursive import will
not work." not work."
(define egg-content (if file (define egg-content (if file
(egg-metadata name file) (egg-metadata name #:file file)
(egg-metadata name))) (egg-metadata name #:version version)))
(if (not egg-content) (if (not egg-content)
(values #f '()) ; egg doesn't exist (values #f '()) ; egg doesn't exist
(let* ((version* (or (assoc-ref egg-content 'version) (let* ((version* (or (assoc-ref egg-content 'version)
@ -326,10 +328,11 @@ (define (maybe-inputs input-type inputs)
(define egg->guix-package/m ;memoized variant (define egg->guix-package/m ;memoized variant
(memoize egg->guix-package)) (memoize egg->guix-package))
(define (egg-recursive-import package-name) (define* (egg-recursive-import package-name #:optional version)
(recursive-import package-name (recursive-import package-name
#:version version
#:repo->guix-package (lambda* (name #:key version repo) #:repo->guix-package (lambda* (name #:key version repo)
(egg->guix-package/m name)) (egg->guix-package/m name version))
#:guix-name egg-name->guix-name)) #:guix-name egg-name->guix-name))

View file

@ -26,6 +26,7 @@ (define-module (guix scripts import egg)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-11) #:use-module (srfi srfi-11)
#:use-module (srfi srfi-37) #:use-module (srfi srfi-37)
#:use-module (srfi srfi-71)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (ice-9 format) #:use-module (ice-9 format)
#:export (guix-import-egg)) #:export (guix-import-egg))
@ -83,7 +84,8 @@ (define (parse-options)
(_ #f)) (_ #f))
(reverse opts)))) (reverse opts))))
(match args (match args
((package-name) ((spec)
(let ((name version (package-name->name+version spec)))
(if (assoc-ref opts 'recursive) (if (assoc-ref opts 'recursive)
;; Recursive import ;; Recursive import
(map (match-lambda (map (match-lambda
@ -91,13 +93,15 @@ (define (parse-options)
`(define-public ,(string->symbol name) `(define-public ,(string->symbol name)
,pkg)) ,pkg))
(_ #f)) (_ #f))
(egg-recursive-import package-name)) (egg-recursive-import name version))
;; Single import ;; Single import
(let ((sexp (egg->guix-package package-name))) (let ((sexp (egg->guix-package name version)))
(unless sexp (unless sexp
(leave (G_ "failed to download meta-data for package '~a'~%") (leave (G_ "failed to download meta-data for package '~a'~%")
package-name)) (if version
sexp))) (string-append name "@" version)
name)))
sexp))))
(() (()
(leave (G_ "too few arguments~%"))) (leave (G_ "too few arguments~%")))
((many ...) ((many ...)