GNU bug report logs - #37322
[PATCH 1/2] adds the capability of importing a specified version to the crate importer

Previous Next

Package: guix-patches;

Reported by: Martin Becze <mjbecze <at> riseup.net>

Date: Fri, 6 Sep 2019 15:33:02 UTC

Severity: normal

Tags: patch

Merged with 37323

Done: Ludovic Courtès <ludo <at> gnu.org>

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 37322 in the body.
You can then email your comments to 37322 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#37322; Package guix-patches. (Fri, 06 Sep 2019 15:33:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Martin Becze <mjbecze <at> riseup.net>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Fri, 06 Sep 2019 15:33:02 GMT) Full text and rfc822 format available.

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

From: Martin Becze <mjbecze <at> riseup.net>
To: guix-patches <at> gnu.org
Cc: Martin Becze <mjbecze <at> riseup.net>
Subject: [PATCH 1/2] adds the capability of importing a specified version to
 the crate importer
Date: Fri,  6 Sep 2019 11:32:10 -0400
---
 guix/import/crate.scm | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index f6057dbf8b..3266ebdfec 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2016 David Craven <david <at> craven.ch>
 ;;; Copyright © 2019 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2019 Martin Becze <mjbecze <at> riseup.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -181,8 +182,8 @@ and LICENSE."
   ;; This regexp matches that.
   (make-regexp "^(.*) OR (.*)$"))
 
-(define (crate->guix-package crate-name)
-  "Fetch the metadata for CRATE-NAME from crates.io, and return the
+(define (crate->guix-package crate-name <at> version)
+  "Fetch the metadata for CRATE-NAME <at> VERSION from crates.io, and return the
 `package' s-expression corresponding to that package, or #f on failure."
   (define (string->license string)
     (match (regexp-exec %dual-license-rx string)
@@ -193,13 +194,29 @@ and LICENSE."
   (define (normal-dependency? dependency)
     (eq? (crate-dependency-kind dependency) 'normal))
 
+  (define crate-name-version-list
+    (let ((lnv (string-split crate-name <at> version #\@)))
+      (if (= 1 (length lnv))
+	  (append lnv '(#f))
+	  lnv)))
+
+  (define crate-name
+    (car crate-name-version-list))
+
+
   (define crate
     (lookup-crate crate-name))
 
+  (define crate-version-string
+    (let ((version (cadr crate-name-version-list)))
+      (if version
+        version
+        (crate-latest-version crate))))
+
   (and crate
        (let* ((version        (find (lambda (version)
                                       (string=? (crate-version-number version)
-                                                (crate-latest-version crate)))
+                                                crate-version-string))
                                     (crate-versions crate)))
               (dependencies   (crate-version-dependencies version))
               (dep-crates     (filter normal-dependency? dependencies))
-- 
2.23.0





Information forwarded to guix-patches <at> gnu.org:
bug#37322; Package guix-patches. (Sun, 08 Sep 2019 12:28:01 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Martin Becze <mjbecze <at> riseup.net>
Cc: 37322 <at> debbugs.gnu.org
Subject: Re: [bug#37322] [PATCH 1/2] adds the capability of importing a
 specified version to the crate importer
Date: Sun, 08 Sep 2019 14:27:48 +0200
Hello Martin,

So the goal is to allow users to run “guix import rust-foo <at> 1.2.3”,
right?  That’s a good idea.

Martin Becze <mjbecze <at> riseup.net> skribis:

> diff --git a/guix/import/crate.scm b/guix/import/crate.scm
> index f6057dbf8b..3266ebdfec 100644
> --- a/guix/import/crate.scm
> +++ b/guix/import/crate.scm
> @@ -1,6 +1,7 @@
>  ;;; GNU Guix --- Functional package management for GNU
>  ;;; Copyright © 2016 David Craven <david <at> craven.ch>
>  ;;; Copyright © 2019 Ludovic Courtès <ludo <at> gnu.org>
> +;;; Copyright © 2019 Martin Becze <mjbecze <at> riseup.net>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -181,8 +182,8 @@ and LICENSE."
>    ;; This regexp matches that.
>    (make-regexp "^(.*) OR (.*)$"))
>  
> -(define (crate->guix-package crate-name)
> -  "Fetch the metadata for CRATE-NAME from crates.io, and return the
> +(define (crate->guix-package crate-name <at> version)
> +  "Fetch the metadata for CRATE-NAME <at> VERSION from crates.io, and return the

The idea is that the (guix import …) modules do not contain UI-related
stuff, and that UI-related stuff is instead isolated in (guix scripts
import …).

Thus, splitting the “crate <at> version” string should happen in (guix
scripts import crate) rather than in this module.

Instead, you could simply change ‘crate->guix-package’ so that it takes
an optional ‘version’ field:

  (define* (crate->guix-package crate-name #:optional version)
    …)

In a second step, you’d change (guix scripts import crate) so that it
passes that version string to ‘crate->guix-package’.

How does that sound?

> +  (define crate-name-version-list
> +    (let ((lnv (string-split crate-name <at> version #\@)))
> +      (if (= 1 (length lnv))
> +	  (append lnv '(#f))
> +	  lnv)))
> +
> +  (define crate-name
> +    (car crate-name-version-list))
> +
> +
>    (define crate
>      (lookup-crate crate-name))
>  
> +  (define crate-version-string
> +    (let ((version (cadr crate-name-version-list)))
> +      (if version
> +        version
> +        (crate-latest-version crate))))

We have a policy of not using ‘cadr’ and friends:

  https://guix.gnu.org/manual/en/html_node/Data-Types-and-Pattern-Matching.html

So the code above would typically look like:

  (define-values (name version)
    (match (string-split crate-spec #\@)
      ((name version) (values name version))
      ((name)         (values name #f))))

Could you send an updated patch (actually two patches)?

Thanks for working on the importer!

Ludo’.




Merged 37322 37323. Request was from Ludovic Courtès <ludo <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 08 Sep 2019 12:29:02 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#37322; Package guix-patches. (Mon, 09 Sep 2019 15:33:02 GMT) Full text and rfc822 format available.

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

From: Martin Becze <mjbecze <at> riseup.net>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 37322 <at> debbugs.gnu.org
Subject: Re: [bug#37322] [PATCH 1/2] adds the capability of importing a
 specified version to the crate importer
Date: Mon, 9 Sep 2019 17:32:36 +0200
yep! thats the idea. I'll fix up the guile soon.

On 9/8/19 2:27 PM, Ludovic Courtès wrote:
> Hello Martin,
>
> So the goal is to allow users to run “guix import rust-foo <at> 1.2.3”,
> right?  That’s a good idea.
>
> Martin Becze <mjbecze <at> riseup.net> skribis:
>
>> diff --git a/guix/import/crate.scm b/guix/import/crate.scm
>> index f6057dbf8b..3266ebdfec 100644
>> --- a/guix/import/crate.scm
>> +++ b/guix/import/crate.scm
>> @@ -1,6 +1,7 @@
>>  ;;; GNU Guix --- Functional package management for GNU
>>  ;;; Copyright © 2016 David Craven <david <at> craven.ch>
>>  ;;; Copyright © 2019 Ludovic Courtès <ludo <at> gnu.org>
>> +;;; Copyright © 2019 Martin Becze <mjbecze <at> riseup.net>
>>  ;;;
>>  ;;; This file is part of GNU Guix.
>>  ;;;
>> @@ -181,8 +182,8 @@ and LICENSE."
>>    ;; This regexp matches that.
>>    (make-regexp "^(.*) OR (.*)$"))
>>  
>> -(define (crate->guix-package crate-name)
>> -  "Fetch the metadata for CRATE-NAME from crates.io, and return the
>> +(define (crate->guix-package crate-name <at> version)
>> +  "Fetch the metadata for CRATE-NAME <at> VERSION from crates.io, and return the
> The idea is that the (guix import …) modules do not contain UI-related
> stuff, and that UI-related stuff is instead isolated in (guix scripts
> import …).
>
> Thus, splitting the “crate <at> version” string should happen in (guix
> scripts import crate) rather than in this module.
>
> Instead, you could simply change ‘crate->guix-package’ so that it takes
> an optional ‘version’ field:
>
>   (define* (crate->guix-package crate-name #:optional version)
>     …)
>
> In a second step, you’d change (guix scripts import crate) so that it
> passes that version string to ‘crate->guix-package’.
>
> How does that sound?
>
>> +  (define crate-name-version-list
>> +    (let ((lnv (string-split crate-name <at> version #\@)))
>> +      (if (= 1 (length lnv))
>> +	  (append lnv '(#f))
>> +	  lnv)))
>> +
>> +  (define crate-name
>> +    (car crate-name-version-list))
>> +
>> +
>>    (define crate
>>      (lookup-crate crate-name))
>>  
>> +  (define crate-version-string
>> +    (let ((version (cadr crate-name-version-list)))
>> +      (if version
>> +        version
>> +        (crate-latest-version crate))))
> We have a policy of not using ‘cadr’ and friends:
>
>   https://guix.gnu.org/manual/en/html_node/Data-Types-and-Pattern-Matching.html
>
> So the code above would typically look like:
>
>   (define-values (name version)
>     (match (string-split crate-spec #\@)
>       ((name version) (values name version))
>       ((name)         (values name #f))))
>
> Could you send an updated patch (actually two patches)?
>
> Thanks for working on the importer!
>
> Ludo’.





Information forwarded to guix-patches <at> gnu.org:
bug#37322; Package guix-patches. (Mon, 09 Sep 2019 15:38:01 GMT) Full text and rfc822 format available.

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

From: Martin Becze <mjbecze <at> riseup.net>
To: 37322 <at> debbugs.gnu.org,
	ludo <at> gnu.org
Cc: Martin Becze <mjbecze <at> riseup.net>
Subject: [PATCH v2 1/2] added versoining to crate import
Date: Mon,  9 Sep 2019 11:36:04 -0400
---
 guix/import/crate.scm         | 12 +++++++++---
 guix/scripts/import/crate.scm | 10 +++++++++-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index f6057dbf8b..de56432e3c 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2016 David Craven <david <at> craven.ch>
 ;;; Copyright © 2019 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2019 Martin Becze <mjbecze <at> riseup.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -181,8 +182,8 @@ and LICENSE."
   ;; This regexp matches that.
   (make-regexp "^(.*) OR (.*)$"))
 
-(define (crate->guix-package crate-name)
-  "Fetch the metadata for CRATE-NAME from crates.io, and return the
+(define (crate->guix-package crate-name version)
+  "Fetch the metadata for CRATE-NAME <at> VERSION from crates.io, and return the
 `package' s-expression corresponding to that package, or #f on failure."
   (define (string->license string)
     (match (regexp-exec %dual-license-rx string)
@@ -196,10 +197,15 @@ and LICENSE."
   (define crate
     (lookup-crate crate-name))
 
+  (define crate-version-string
+      (if version
+        version
+        (crate-latest-version crate)))
+
   (and crate
        (let* ((version        (find (lambda (version)
                                       (string=? (crate-version-number version)
-                                                (crate-latest-version crate)))
+                                                crate-version-string))
                                     (crate-versions crate)))
               (dependencies   (crate-version-dependencies version))
               (dep-crates     (filter normal-dependency? dependencies))
diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm
index cab9a4397b..948b90ec15 100644
--- a/guix/scripts/import/crate.scm
+++ b/guix/scripts/import/crate.scm
@@ -2,6 +2,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2014 David Thompson <davet <at> gnu.org>
 ;;; Copyright © 2016 David Craven <david <at> craven.ch>
+;;; Copyright © 2019 Martin Becze <mjbecze <at> riseup.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -66,6 +67,7 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
 ;;;
 
 (define (guix-import-crate . args)
+
   (define (parse-options)
     ;; Return the alist of option values.
     (args-fold* args %options
@@ -75,6 +77,7 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
                   (alist-cons 'argument arg result))
                 %default-options))
 
+
   (let* ((opts (parse-options))
          (args (filter-map (match-lambda
                             (('argument . value)
@@ -83,7 +86,12 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
                            (reverse opts))))
     (match args
       ((package-name)
-       (let ((sexp (crate->guix-package package-name)))
+       (define-values (name version)
+            (match (string-split package-name #\@)
+            ((name version) (values name version))
+            ((name) (values name #f))))
+ 
+       (let ((sexp (crate->guix-package name version)))
          (unless sexp
            (leave (G_ "failed to download meta-data for package '~a'~%")
                   package-name))
-- 
2.23.0





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Mon, 09 Sep 2019 22:39:02 GMT) Full text and rfc822 format available.

Notification sent to Martin Becze <mjbecze <at> riseup.net>:
bug acknowledged by developer. (Mon, 09 Sep 2019 22:39:02 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Martin Becze <mjbecze <at> riseup.net>
Cc: 37322-done <at> debbugs.gnu.org
Subject: Re: [bug#37322] [PATCH v2 1/2] added versoining to crate import
Date: Tue, 10 Sep 2019 00:38:50 +0200
Hi Martin,

Martin Becze <mjbecze <at> riseup.net> skribis:

> ---
>  guix/import/crate.scm         | 12 +++++++++---
>  guix/scripts/import/crate.scm | 10 +++++++++-
>  2 files changed, 18 insertions(+), 4 deletions(-)

Pushed as fd63ecbe050bf8fa7c8ff0a003d56cce97b6ded1.  I tweaked quite a
few things, mostly for cosmetic reasons, and added a commit log that
follows our conventions.  Please take a look!

Thank you,
Ludo’.




Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Mon, 09 Sep 2019 22:39:02 GMT) Full text and rfc822 format available.

Notification sent to Martin Becze <mjbecze <at> riseup.net>:
bug acknowledged by developer. (Mon, 09 Sep 2019 22:39:02 GMT) Full text and rfc822 format available.

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

This bug report was last modified 4 years and 199 days ago.

Previous Next


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