From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:41315) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6wIW-00073F-KQ for guix-patches@gnu.org; Sun, 08 Sep 2019 08:28:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6wIU-0005Q6-0m for guix-patches@gnu.org; Sun, 08 Sep 2019 08:28:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i6wIT-0005Q1-Tt for guix-patches@gnu.org; Sun, 08 Sep 2019 08:28:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i6wIT-0003Nu-Pa for guix-patches@gnu.org; Sun, 08 Sep 2019 08:28:01 -0400 Subject: [bug#37322] [PATCH 1/2] adds the capability of importing a specified version to the crate importer Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20190906153211.8613-1-mjbecze@riseup.net> Date: Sun, 08 Sep 2019 14:27:48 +0200 In-Reply-To: <20190906153211.8613-1-mjbecze@riseup.net> (Martin Becze's message of "Fri, 6 Sep 2019 11:32:10 -0400") Message-ID: <877e6j9dmj.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Martin Becze Cc: 37322@debbugs.gnu.org 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=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 return = the The idea is that the (guix import =E2=80=A6) modules do not contain UI-rela= ted 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 happen in= (guix scripts import crate) rather than in this module. Instead, you could simply change =E2=80=98crate->guix-package=E2=80=99 so t= hat 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 that = 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=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-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=E2=80=99.