From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:54942) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7Lf6-0002Zj-Rm for guix-patches@gnu.org; Mon, 09 Sep 2019 11:33:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7Lf5-0000uz-3K for guix-patches@gnu.org; Mon, 09 Sep 2019 11:33:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:59845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7Lf4-0000uW-7E for guix-patches@gnu.org; Mon, 09 Sep 2019 11:33:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i7Lf4-00013F-3U for guix-patches@gnu.org; Mon, 09 Sep 2019 11:33:02 -0400 Subject: [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Resent-Message-ID: References: <20190906153211.8613-1-mjbecze@riseup.net> <877e6j9dmj.fsf@gnu.org> From: Martin Becze Message-ID: Date: Mon, 9 Sep 2019 17:32:36 +0200 MIME-Version: 1.0 In-Reply-To: <877e6j9dmj.fsf@gnu.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 37322@debbugs.gnu.org yep! thats the idea. I'll fix up the guile soon. On 9/8/19 2:27 PM, Ludovic Court=C3=A8s wrote: > Hello Martin, > > So the goal is to allow users to run =E2=80=9Cguix import rust-foo@1.2.= 3=E2=80=9D, > right? That=E2=80=99s a good idea. > > Martin Becze 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 =C2=A9 2016 David Craven >> ;;; Copyright =C2=A9 2019 Ludovic Court=C3=A8s >> +;;; Copyright =C2=A9 2019 Martin Becze >> ;;; >> ;;; This file is part of GNU Guix. >> ;;; >> @@ -181,8 +182,8 @@ and LICENSE." >> ;; This regexp matches that. >> (make-regexp "^(.*) OR (.*)$")) >> =20 >> -(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 retu= rn the > The idea is that the (guix import =E2=80=A6) modules do not contain UI-= related > stuff, and that UI-related stuff is instead isolated in (guix scripts > import =E2=80=A6). > > Thus, splitting the =E2=80=9Ccrate@version=E2=80=9D string should happe= n in (guix > scripts import crate) rather than in this module. > > Instead, you could simply change =E2=80=98crate->guix-package=E2=80=99 = so that it takes > an optional =E2=80=98version=E2=80=99 field: > > (define* (crate->guix-package crate-name #:optional version) > =E2=80=A6) > > In a second step, you=E2=80=99d change (guix scripts import crate) so t= hat it > passes that version string to =E2=80=98crate->guix-package=E2=80=99. > > How does that sound? > >> + (define crate-name-version-list >> + (let ((lnv (string-split crate-name@version #\@))) >> + (if (=3D 1 (length lnv)) >> + (append lnv '(#f)) >> + lnv))) >> + >> + (define crate-name >> + (car crate-name-version-list)) >> + >> + >> (define crate >> (lookup-crate crate-name)) >> =20 >> + (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 =E2=80=98cadr=E2=80=99 and friends: > > https://guix.gnu.org/manual/en/html_node/Data-Types-and-Pattern-Match= ing.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=E2=80=99.