[PATCH] guix: import: cpan: add recursive

  • Open
  • quality assurance status badge
Details
One participant
  • zero@fedora
Owner
unassigned
Submitted by
zero@fedora
Severity
normal
Z
Z
zero@fedora wrote on 10 Jan 01:41 +0100
(address . guix-patches@gnu.org)(name . zero@fedora)(address . shinyzero0@tilde.club)
1607241d782b7dc97cc5775903c50a81ef3b39ec.1704847312.git.shinyzero0@tilde.club
Change-Id: Id167c7ddd079f4e04650ce7cc1692a9de36cd8fe
---
guix/import/cpan.scm | 63 ++++++++++++++++++++++--------------
guix/scripts/import/cpan.scm | 25 +++++++++++---
2 files changed, 58 insertions(+), 30 deletions(-)

Toggle diff (152 lines)
diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm
index b87736eef6..2090da275d 100644
--- a/guix/import/cpan.scm
+++ b/guix/import/cpan.scm
@@ -37,12 +37,13 @@ (define-module (guix import cpan)
#:use-module (guix utils)
#:use-module (guix base32)
#:use-module ((guix download) #:select (download-to-store url-fetch))
- #:use-module ((guix import utils) #:select (factorize-uri))
+ #:use-module (guix import utils)
#:use-module (guix import json)
#:use-module (guix packages)
#:use-module (guix upstream)
#:use-module (guix derivations)
#:export (cpan->guix-package
+ cpan-recursive-import
metacpan-url->mirror-url
%cpan-updater
@@ -284,35 +285,42 @@ (define (cpan-module->sexp release)
upstream-input-downstream-name)
inputs)))))))
- (let ((tarball (with-store store
+ (let* ((tarball (with-store store
(download-to-store store source-url)))
- (inputs (cpan-module-inputs release)))
- `(package
- (name ,(cpan-name->downstream-name name))
- (version ,version)
- (source (origin
- (method url-fetch)
- (uri (string-append ,@(factorize-uri source-url version)))
- (sha256
- (base32
- ,(bytevector->nix-base32-string (file-sha256 tarball))))))
- (build-system perl-build-system)
- ,@(maybe-inputs 'native-inputs
- (filter (upstream-input-type-predicate 'native)
- inputs))
- ,@(maybe-inputs 'propagated-inputs
- (filter (upstream-input-type-predicate 'propagated)
- inputs))
- (home-page ,(cpan-home name))
- (synopsis ,(cpan-release-abstract release))
- (description fill-in-yourself!)
- (license ,(string->license (cpan-release-license release))))))
+ (inputs (cpan-module-inputs release))
+ (sexp
+ `(package
+ (name ,(cpan-name->downstream-name name))
+ (version ,version)
+ (source (origin
+ (method url-fetch)
+ (uri (string-append ,@(factorize-uri source-url version)))
+ (sha256
+ (base32
+ ,(bytevector->nix-base32-string (file-sha256 tarball))))))
+ (build-system perl-build-system)
+ ,@(maybe-inputs 'native-inputs
+ (filter (upstream-input-type-predicate 'native)
+ inputs))
+ ,@(maybe-inputs 'propagated-inputs
+ (filter (upstream-input-type-predicate 'propagated)
+ inputs))
+ (home-page ,(cpan-home name))
+ (synopsis ,(cpan-release-abstract release))
+ (description fill-in-yourself!)
+ (license ,(string->license (cpan-release-license release))))))
+ (values
+ sexp
+ (map upstream-input-name inputs))
+ ))
-(define (cpan->guix-package module-name)
+(define* (cpan->guix-package module-name #:key version #:allow-other-keys)
"Fetch the metadata for PACKAGE-NAME from metacpan.org, and return the
`package' s-expression corresponding to that package, or #f on failure."
(let ((release (cpan-fetch (module->name module-name))))
- (and=> release cpan-module->sexp)))
+ (if release
+ (cpan-module->sexp release)
+ (values #f '()))))
(define cpan-package?
(let ((cpan-rx (make-regexp (string-append "("
@@ -357,6 +365,11 @@ (define* (latest-release package #:key (version #f))
(urls (list url))
(inputs (cpan-module-inputs release)))))))
+(define* (cpan-recursive-import package-name)
+ (recursive-import package-name
+ #:repo->guix-package cpan->guix-package
+ #:guix-name (compose cpan-name->downstream-name module->name)))
+
(define %cpan-updater
(upstream-updater
(name 'cpan)
diff --git a/guix/scripts/import/cpan.scm b/guix/scripts/import/cpan.scm
index bdf5a1e423..cab6424068 100644
--- a/guix/scripts/import/cpan.scm
+++ b/guix/scripts/import/cpan.scm
@@ -43,6 +43,9 @@ (define (show-help)
Import and convert the CPAN package for PACKAGE-NAME.\n"))
(display (G_ "
-h, --help display this help and exit"))
+ (display (G_ "
+ -r, --recursive generate package expressions for all Gem packages\
+ that are not yet in Guix"))
(display (G_ "
-V, --version display version information and exit"))
(newline)
@@ -54,6 +57,9 @@ (define %options
(lambda args
(show-help)
(exit 0)))
+ (option '(#\r "recursive") #f #f
+ (lambda (opt name arg result)
+ (alist-cons 'recursive #t result)))
(option '(#\V "version") #f #f
(lambda args
(show-version-and-exit "guix import cpan")))
@@ -78,11 +84,20 @@ (define (guix-import-cpan . args)
(reverse opts))))
(match args
((package-name)
- (let ((sexp (cpan->guix-package package-name)))
- (unless sexp
- (leave (G_ "failed to download meta-data for package '~a'~%")
- package-name))
- sexp))
+ (let ((sexp
+ (if (assoc-ref opts 'recursive)
+ (map (match-lambda
+ ((and ('package ('name name) . rest) pkg)
+ `(define-public ,(string->symbol name)
+ ,pkg))
+ (_ #f))
+ (cpan-recursive-import package-name))
+ (let ((sexp (cpan->guix-package package-name)))
+ sexp))))
+ (unless sexp
+ (leave (G_ "failed to download meta-data for package '~a'~%")
+ package-name))
+ sexp))
(()
(leave (G_ "too few arguments~%")))
((many ...)

base-commit: 931d893c550128591018587c90d2491fd66a11a4
--
2.43.0
Z
Z
zero@fedora wrote on 10 Jan 02:29 +0100
(address . 68358@debbugs.gnu.org)(name . zero@fedora)(address . shinyzero0@tilde.club)
7a6b50a5af6f276034ffffcd24ad824fd52df35c.1704850195.git.shinyzero0@tilde.club
* guix/import/cpan.scm: new function, some changes to make recursive import possible
* guix/scripts/import/cpan.scm: add recursive import

Change-Id: Id167c7ddd079f4e04650ce7cc1692a9de36cd8fe
---
guix/import/cpan.scm | 63 ++++++++++++++++++++++--------------
guix/scripts/import/cpan.scm | 25 +++++++++++---
2 files changed, 58 insertions(+), 30 deletions(-)

Toggle diff (152 lines)
diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm
index b87736eef6..2090da275d 100644
--- a/guix/import/cpan.scm
+++ b/guix/import/cpan.scm
@@ -37,12 +37,13 @@ (define-module (guix import cpan)
#:use-module (guix utils)
#:use-module (guix base32)
#:use-module ((guix download) #:select (download-to-store url-fetch))
- #:use-module ((guix import utils) #:select (factorize-uri))
+ #:use-module (guix import utils)
#:use-module (guix import json)
#:use-module (guix packages)
#:use-module (guix upstream)
#:use-module (guix derivations)
#:export (cpan->guix-package
+ cpan-recursive-import
metacpan-url->mirror-url
%cpan-updater
@@ -284,35 +285,42 @@ (define (cpan-module->sexp release)
upstream-input-downstream-name)
inputs)))))))
- (let ((tarball (with-store store
+ (let* ((tarball (with-store store
(download-to-store store source-url)))
- (inputs (cpan-module-inputs release)))
- `(package
- (name ,(cpan-name->downstream-name name))
- (version ,version)
- (source (origin
- (method url-fetch)
- (uri (string-append ,@(factorize-uri source-url version)))
- (sha256
- (base32
- ,(bytevector->nix-base32-string (file-sha256 tarball))))))
- (build-system perl-build-system)
- ,@(maybe-inputs 'native-inputs
- (filter (upstream-input-type-predicate 'native)
- inputs))
- ,@(maybe-inputs 'propagated-inputs
- (filter (upstream-input-type-predicate 'propagated)
- inputs))
- (home-page ,(cpan-home name))
- (synopsis ,(cpan-release-abstract release))
- (description fill-in-yourself!)
- (license ,(string->license (cpan-release-license release))))))
+ (inputs (cpan-module-inputs release))
+ (sexp
+ `(package
+ (name ,(cpan-name->downstream-name name))
+ (version ,version)
+ (source (origin
+ (method url-fetch)
+ (uri (string-append ,@(factorize-uri source-url version)))
+ (sha256
+ (base32
+ ,(bytevector->nix-base32-string (file-sha256 tarball))))))
+ (build-system perl-build-system)
+ ,@(maybe-inputs 'native-inputs
+ (filter (upstream-input-type-predicate 'native)
+ inputs))
+ ,@(maybe-inputs 'propagated-inputs
+ (filter (upstream-input-type-predicate 'propagated)
+ inputs))
+ (home-page ,(cpan-home name))
+ (synopsis ,(cpan-release-abstract release))
+ (description fill-in-yourself!)
+ (license ,(string->license (cpan-release-license release))))))
+ (values
+ sexp
+ (map upstream-input-name inputs))
+ ))
-(define (cpan->guix-package module-name)
+(define* (cpan->guix-package module-name #:key version #:allow-other-keys)
"Fetch the metadata for PACKAGE-NAME from metacpan.org, and return the
`package' s-expression corresponding to that package, or #f on failure."
(let ((release (cpan-fetch (module->name module-name))))
- (and=> release cpan-module->sexp)))
+ (if release
+ (cpan-module->sexp release)
+ (values #f '()))))
(define cpan-package?
(let ((cpan-rx (make-regexp (string-append "("
@@ -357,6 +365,11 @@ (define* (latest-release package #:key (version #f))
(urls (list url))
(inputs (cpan-module-inputs release)))))))
+(define* (cpan-recursive-import package-name)
+ (recursive-import package-name
+ #:repo->guix-package cpan->guix-package
+ #:guix-name (compose cpan-name->downstream-name module->name)))
+
(define %cpan-updater
(upstream-updater
(name 'cpan)
diff --git a/guix/scripts/import/cpan.scm b/guix/scripts/import/cpan.scm
index bdf5a1e423..cab6424068 100644
--- a/guix/scripts/import/cpan.scm
+++ b/guix/scripts/import/cpan.scm
@@ -43,6 +43,9 @@ (define (show-help)
Import and convert the CPAN package for PACKAGE-NAME.\n"))
(display (G_ "
-h, --help display this help and exit"))
+ (display (G_ "
+ -r, --recursive generate package expressions for all Gem packages\
+ that are not yet in Guix"))
(display (G_ "
-V, --version display version information and exit"))
(newline)
@@ -54,6 +57,9 @@ (define %options
(lambda args
(show-help)
(exit 0)))
+ (option '(#\r "recursive") #f #f
+ (lambda (opt name arg result)
+ (alist-cons 'recursive #t result)))
(option '(#\V "version") #f #f
(lambda args
(show-version-and-exit "guix import cpan")))
@@ -78,11 +84,20 @@ (define (guix-import-cpan . args)
(reverse opts))))
(match args
((package-name)
- (let ((sexp (cpan->guix-package package-name)))
- (unless sexp
- (leave (G_ "failed to download meta-data for package '~a'~%")
- package-name))
- sexp))
+ (let ((sexp
+ (if (assoc-ref opts 'recursive)
+ (map (match-lambda
+ ((and ('package ('name name) . rest) pkg)
+ `(define-public ,(string->symbol name)
+ ,pkg))
+ (_ #f))
+ (cpan-recursive-import package-name))
+ (let ((sexp (cpan->guix-package package-name)))
+ sexp))))
+ (unless sexp
+ (leave (G_ "failed to download meta-data for package '~a'~%")
+ package-name))
+ sexp))
(()
(leave (G_ "too few arguments~%")))
((many ...)

base-commit: 931d893c550128591018587c90d2491fd66a11a4
--
2.43.0
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 68358@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 68358
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch