From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id YDmKIr/Zo2Ua4wAAqHPOHw:P1 (envelope-from ) for ; Sun, 14 Jan 2024 13:55:27 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id YDmKIr/Zo2Ua4wAAqHPOHw (envelope-from ) for ; Sun, 14 Jan 2024 13:55:27 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=posteo.net header.s=2017 header.b=NOxofeIj; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (strict)" header.from=posteo.net (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1705236927; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=Y/VlXWoIHutNKv900nPzPvpK7+g+dnbsuu8F917kYjU=; b=md8nIl8m0U2DKNn/Lk08YwZs3fJ3jIEQ50m6CMX5r49p8LE7f7EVEGZATAj/sJvugRFjNt w/7doD7cpB0crBRknweJ4qU7S0/eritxhiAukfjWvjK7jA7Pkll0g2ludiTU1t2gky0kf3 2pGNk9Db860Cx3JQLkisAa75Ja8K6IHXC8W/dYXSwGlIveWdE8iCNOZaeTAeqhi/UZXar/ uo2qM1dlbQJwQ0Qtjv9jcAw6/NhRFTXVF71N9SURPi5UwqEqu/ApSq3mqSeHh4ea4vg483 kClIow+SRfqo7QzOlHA4MRr36g4okhpaFBw65ePBRPfWbXEW4RwIaY5Xbk50uQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=posteo.net header.s=2017 header.b=NOxofeIj; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (strict)" header.from=posteo.net (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1705236927; a=rsa-sha256; cv=none; b=eMnV3TrjYHIqk3yz2bW9oD00Zhe/ucCYyu0X0+E7066RlR4gGWProxtRZi+f3GzOBUvWDt xxu6O7tXxiMi/LPQ8NixszevvzmHXWgJ6dTudo6n5AQkmYvJ/szOSnFAEcGc0m5aGf5WBd fINP7NmtSGMeKuPKf78gkmbtMTWnjToLAm1x/fRqc3atbJdW8VYkby1u8JmUXZinXCZmaU 5rHS8Y5I0BBMkgt3AwBXQkqqvn0fQvFepfleNw6dFOwHFXUsspvDypfoOZVdAs1lrLJJEm 4KdiANfXrd0T4UvnU4+3PcjWhxEV5y0UWcI1icVjlX84OxHQ32Ct/wj98M9Dng== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 27D4A3FE06 for ; Sun, 14 Jan 2024 13:55:27 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rP014-0006b0-Bt; Sun, 14 Jan 2024 07:55:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rP012-0006ar-R5 for guix-patches@gnu.org; Sun, 14 Jan 2024 07:55:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rP011-0001FC-Bj for guix-patches@gnu.org; Sun, 14 Jan 2024 07:55:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rP010-0000i1-4t for guix-patches@gnu.org; Sun, 14 Jan 2024 07:55:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68346] [PATCH 0/2] semver aware cargo refresh Resent-From: David Elsing Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 14 Jan 2024 12:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68346 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: efraim@flashner.co.il, 68346@debbugs.gnu.org Cc: Jaeme Sifat , Efraim Flashner X-Debbugs-Original-To: Efraim Flashner , guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17052368882699 (code B ref -1); Sun, 14 Jan 2024 12:55:02 +0000 Received: (at submit) by debbugs.gnu.org; 14 Jan 2024 12:54:48 +0000 Received: from localhost ([127.0.0.1]:41858 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rP00l-0000hS-Pz for submit@debbugs.gnu.org; Sun, 14 Jan 2024 07:54:48 -0500 Received: from lists.gnu.org ([2001:470:142::17]:37276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rP00k-0000hE-Ad for submit@debbugs.gnu.org; Sun, 14 Jan 2024 07:54:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rP00e-0006Yf-3w for guix-patches@gnu.org; Sun, 14 Jan 2024 07:54:41 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rP00Z-0000qm-Eb for guix-patches@gnu.org; Sun, 14 Jan 2024 07:54:39 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 8806A240028 for ; Sun, 14 Jan 2024 13:54:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705236869; bh=wrnEFWBR3hb5o8ewKrpmWyHPNF77cnMBnCvxW++Bj0g=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=NOxofeIjkT8phF34PVlUrRkrgCI2azT/bRp/wv2pnYrwfUTI1q+v5Kuknopv5k4AT 4pXYjTOrNJK8PAPVDQ7olS8ZFYZeXKaoiCS2isiXpmjIPDtitsTWs5ALNW/I+jak1N jUlcam1v1jgxje9/AkfyroKvE7aHN0mANFhupjD3Fhd2/u5CeSHMQmyIXj18P/4k5d T/7B+3FtgZVSsvRXLjEHr8Dqk4y2AdxvIFHfwWqLYgIjGOKmIuZhRg60LfuV24ptgk 50nzRJlhGodtxGc6tdg90SXDCp5+V0vSIwGkgKpdHfbnO8YvWMes+6EtQhatfl+HD5 qiYTRvX7JwqAw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TCZwh5ZQdz9rxK; Sun, 14 Jan 2024 13:54:28 +0100 (CET) From: David Elsing In-Reply-To: References: Date: Sun, 14 Jan 2024 12:54:27 +0000 Message-ID: <86mst8vzwc.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=david.elsing@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: 2.12 X-Migadu-Queue-Id: 27D4A3FE06 X-Spam-Score: 2.12 X-Migadu-Scanner: mx11.migadu.com X-TUID: YSQ+nhkVefUV Hello, Efraim Flashner writes: > These patches make 'guix refresh' take into account the semver of the > crate and only suggest upgrading to one which still matches the semver > constraints and isn't yanked. Then I went and used the functions to > factor out some of the other code. thanks for cleaning this up a bit! I tested your patches and only found the (minor) issue that an exception is thrown instead of returning #f if there is no non-yanked package available. The minimum element can also be found without sorting, so I would suggest something like the following changes: diff --git a/guix/import/crate.scm b/guix/import/crate.scm index ba2bc1573e..76b7c05072 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -104,7 +104,7 @@ (define-json-mapping make-crate-dependency ;; Autoload Guile-Semver so we only have a soft dependency. (module-autoload! (current-module) - '(semver) '(string->semver semver->string semversemver semver->string semver?)) (module-autoload! (current-module) '(semver ranges) '(string->semver-range semver-range-contains?)) @@ -233,20 +233,32 @@ (define (string->license string) 'unknown-license!))) (string-split string (string->char-set " /")))) +(define (min-element l less) + "Returns the smallest element of l according to less or #f if l is empty." + + (let loop ((curr #f) + (remaining l)) + (if (null-list? remaining) + curr + (let ((next (car remaining)) + (remaining (cdr remaining))) + (if (and curr + (not (less next curr))) + (loop curr remaining) + (loop next remaining)))))) + (define (max-crate-version-of-semver semver-range range) "Returns a of the highest version within the semver range." - (let ((matching-crates - (sort - (filter (lambda (entry) - (semver-range-contains? - semver-range - (string->semver (crate-version-number entry)))) - range) - (lambda (entry1 entry2) - (version>? (crate-version-number entry1) - (crate-version-number entry2)))))) - (and (not (null-list? matching-crates)) - (first matching-crates)))) + + (define (crate->semver crate) + (string->semver (crate-version-number crate))) + + (min-element + (filter (lambda (crate) + (semver-range-contains? semver-range (crate->semver crate))) + range) + (lambda args + (apply semver>? (map crate->semver args))))) (define (nonyanked-crate-versions crate) "Returns a list of s which are not yanked by upstream." @@ -284,8 +296,8 @@ (define version-number ;; Packages previously marked as yanked take lower priority. (define (find-package-version name range) (let* ((semver-range (string->semver-range range)) - (package-versions - (sort + (version + (min-element (filter (match-lambda ((semver yanked) (and (or allow-yanked? (not yanked)) @@ -293,17 +305,17 @@ (define (find-package-version name range) (map (lambda (pkg) (let ((version (package-version pkg))) (list - (string->semver version) - (assoc-ref (package-properties pkg) - 'crate-version-yanked?)))) + (string->semver version) + (assoc-ref (package-properties pkg) + 'crate-version-yanked?)))) (find-packages-by-name (crate-name->package-name name)))) (match-lambda* (((semver1 yanked1) (semver2 yanked2)) - (or (and yanked1 (not yanked2)) - (and (eq? yanked1 yanked2) - (semver? semver1 semver2)))))))) + (and (not (eq? #f version)) + (match-let (((semver yanked) version)) (list (semver->string semver) yanked))))) ;; Find the highest version of a crate that fulfills the semver . @@ -449,18 +461,22 @@ (define* (import-release package #:key (version #f)) "Return an for the latest release of PACKAGE. Optionally include a VERSION string to fetch a specific version." (let* ((crate-name (guix-package->crate-name package)) - (crate (lookup-crate crate-name)) - (version (or version - (crate-version-number - (max-crate-version-of-semver - (string->semver-range - (string-append "^" (package-version package))) - (nonyanked-crate-versions crate))))) - (url (crate-uri crate-name version))) - (upstream-source - (package (package-name package)) - (version version) - (urls (list url))))) + (crate (lookup-crate crate-name)) + (version + (or version + (let ((max-crate-version + (max-crate-version-of-semver + (string->semver-range + (string-append "^" (package-version package))) + (nonyanked-crate-versions crate)))) + (and max-crate-version + (crate-version-number max-crate-version)))))) + (if version + (upstream-source + (package (package-name package)) + (version version) + (urls (list (crate-uri crate-name version)))) + #f))) (define %crate-updater (upstream-updater Cheers, David