unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer
@ 2019-09-06 15:32 Martin Becze
  2019-09-06 15:32 ` [bug#37323] [PATCH 2/2] updated import crate docs Martin Becze
  2019-09-08 12:27 ` [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Ludovic Courtès
  0 siblings, 2 replies; 4+ messages in thread
From: Martin Becze @ 2019-09-06 15:32 UTC (permalink / raw)
  To: 37322; +Cc: Martin Becze

---
 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@craven.ch>
 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2019 Martin Becze <mjbecze@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@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@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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#37323] [PATCH 2/2] updated import crate docs
  2019-09-06 15:32 [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Martin Becze
@ 2019-09-06 15:32 ` Martin Becze
  2019-09-08 12:27 ` [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Ludovic Courtès
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Becze @ 2019-09-06 15:32 UTC (permalink / raw)
  To: 37323; +Cc: Martin Becze

---
 doc/guix.texi | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 6d6a09b36b..5c568cf929 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -8907,8 +8907,14 @@ in Guix.
 
 @item crate
 @cindex crate
-Import metadata from the crates.io Rust package repository
-@uref{https://crates.io, crates.io}.
+Import metadata from the @uref{https://crates.io, crates.io} Rust package repository.
+
+A specific package version may optionally be specified by following the
+package name by an at-sign and a version number as in the following example:
+
+@example
+guix import crate rand@@0.6.5
+@end example
 
 @item opam
 @cindex OPAM
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer
  2019-09-06 15:32 [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Martin Becze
  2019-09-06 15:32 ` [bug#37323] [PATCH 2/2] updated import crate docs Martin Becze
@ 2019-09-08 12:27 ` Ludovic Courtès
  2019-09-09 15:32   ` Martin Becze
  1 sibling, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2019-09-08 12:27 UTC (permalink / raw)
  To: Martin Becze; +Cc: 37322

Hello Martin,

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

Martin Becze <mjbecze@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@craven.ch>
>  ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
> +;;; Copyright © 2019 Martin Becze <mjbecze@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@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@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@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’.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer
  2019-09-08 12:27 ` [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Ludovic Courtès
@ 2019-09-09 15:32   ` Martin Becze
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Becze @ 2019-09-09 15:32 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 37322

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@1.2.3”,
> right?  That’s a good idea.
>
> Martin Becze <mjbecze@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@craven.ch>
>>  ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
>> +;;; Copyright © 2019 Martin Becze <mjbecze@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@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@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@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’.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-09 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 15:32 [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Martin Becze
2019-09-06 15:32 ` [bug#37323] [PATCH 2/2] updated import crate docs Martin Becze
2019-09-08 12:27 ` [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Ludovic Courtès
2019-09-09 15:32   ` Martin Becze

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).