GNU bug report logs -
#68346
[PATCH 0/2] semver aware cargo refresh
Previous Next
Reported by: Efraim Flashner <efraim <at> flashner.co.il>
Date: Tue, 9 Jan 2024 13:07:01 UTC
Severity: normal
Tags: patch
Done: Efraim Flashner <efraim <at> flashner.co.il>
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 68346 in the body.
You can then email your comments to 68346 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
efraim <at> flashner.co.il, guix-patches <at> gnu.org
:
bug#68346
; Package
guix-patches
.
(Tue, 09 Jan 2024 13:07:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Efraim Flashner <efraim <at> flashner.co.il>
:
New bug report received and forwarded. Copy sent to
efraim <at> flashner.co.il, guix-patches <at> gnu.org
.
(Tue, 09 Jan 2024 13:07:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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.
Efraim Flashner (2):
import: crate: Update to latest semver version.
import: crate: Simplify find-crate-version.
guix/import/crate.scm | 59 +++++++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 22 deletions(-)
base-commit: b26926189e5bf253093050f9a73f2d9d7555cc3e
--
Efraim Flashner <efraim <at> flashner.co.il> רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
Information forwarded
to
efraim <at> flashner.co.il, guix-patches <at> gnu.org
:
bug#68346
; Package
guix-patches
.
(Tue, 09 Jan 2024 13:09:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 68346 <at> debbugs.gnu.org (full text, mbox):
* guix/import/crate.scm (max-crate-version-of-semver,
nonyanked-crate-versions): New procedures.
(import-release)[version]: Update to the requested version or the newest
semver-compatible version.
Change-Id: I72b081147c4eb9faf482f159b7145aaaf9f91f29
---
guix/import/crate.scm | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index c57bd0bc6a..43f80f3fb7 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -5,7 +5,7 @@
;;; Copyright © 2021 Nicolas Goaziou <mail <at> nicolasgoaziou.fr>
;;; Copyright © 2022 Hartmut Goebel <h.goebel <at> crazy-compilers.com>
;;; Copyright © 2023 Simon Tournier <zimon.toutoune <at> gmail.com>
-;;; Copyright © 2023 Efraim Flashner <efraim <at> flashner.co.il>
+;;; Copyright © 2023, 2024 Efraim Flashner <efraim <at> flashner.co.il>
;;; Copyright © 2023 David Elsing <david.elsing <at> posteo.net>
;;;
;;; This file is part of GNU Guix.
@@ -233,6 +233,27 @@ (define (string->license string)
'unknown-license!)))
(string-split string (string->char-set " /"))))
+(define (max-crate-version-of-semver semver-range range)
+ "Returns a <crate-version> 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 (nonyanked-crate-versions crate)
+ "Returns a list of <crate-version>s which are not yanked by upstream."
+ (filter (lambda (entry)
+ (not (crate-version-yanked? entry)))
+ (crate-versions crate)))
+
(define* (crate->guix-package
crate-name
#:key version include-dev-deps? allow-yanked? #:allow-other-keys)
@@ -427,6 +448,7 @@ (define (guix-package->crate-name package)
(define (crate-name->package-name name)
(guix-name "rust-" name))
+
;;;
;;; Updater
@@ -440,7 +462,12 @@ (define* (import-release package #:key (version #f))
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-latest-version crate)))
+ (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))
--
Efraim Flashner <efraim <at> flashner.co.il> רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
Information forwarded
to
efraim <at> flashner.co.il, guix-patches <at> gnu.org
:
bug#68346
; Package
guix-patches
.
(Tue, 09 Jan 2024 13:09:03 GMT)
Full text and
rfc822 format available.
Message #11 received at 68346 <at> debbugs.gnu.org (full text, mbox):
* guix/import/crate.scm (find-crate-version): Reuse
nonyanked-crate-versions, max-crate-version-of-semver.
Change-Id: I976a3b5a397f0d6a7d723804a98356544bfc7da3
---
guix/import/crate.scm | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 43f80f3fb7..ba2bc1573e 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -310,26 +310,14 @@ (define* (crate->guix-package
;; If no matching non-yanked version has been found and allow-yanked? is #t,
;; also consider yanked packages.
(define (find-crate-version crate range)
- (let* ((semver-range (string->semver-range range))
- (versions
- (sort
- (filter (lambda (entry)
- (and
- (or allow-yanked?
- (not (crate-version-yanked? (second entry))))
- (semver-range-contains? semver-range (first entry))))
- (map (lambda (ver)
- (list (string->semver (crate-version-number ver))
- ver))
- (crate-versions crate)))
- (match-lambda* (((semver ver) ...)
- (match-let (((yanked1 yanked2)
- (map crate-version-yanked? ver)))
- (or (and yanked1 (not yanked2))
- (and (eq? yanked1 yanked2)
- (apply semver<? semver)))))))))
- (and (not (null-list? versions))
- (second (last versions)))))
+ (let ((semver-range (string->semver-range range))
+ (versions (nonyanked-crate-versions crate)))
+ (or (and (not (null-list? versions))
+ (max-crate-version-of-semver semver-range versions))
+ (and allow-yanked?
+ (not (null-list? (crate-versions crate)))
+ (max-crate-version-of-semver semver-range
+ (crate-versions crate))))))
;; If no non-yanked existing package version was found, check the upstream
;; versions. If a non-yanked upsteam version exists, use it instead,
--
Efraim Flashner <efraim <at> flashner.co.il> רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
Information forwarded
to
guix-patches <at> gnu.org
:
bug#68346
; Package
guix-patches
.
(Sun, 14 Jan 2024 12:55:02 GMT)
Full text and
rfc822 format available.
Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):
Hello,
Efraim Flashner <efraim <at> flashner.co.il> 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 <crate-dependency> make-crate-dependency
;; Autoload Guile-Semver so we only have a soft dependency.
(module-autoload! (current-module)
- '(semver) '(string->semver semver->string semver<? semver=?))
+ '(semver) '(string->semver semver->string semver<? semver=? 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 <crate-version> 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 <crate-version>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 (null-list? package-versions))
- (match-let (((semver yanked) (last package-versions)))
+ (and (or (not yanked1) yanked2)
+ (or (not (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 <range>.
@@ -449,18 +461,22 @@ (define* (import-release package #:key (version #f))
"Return an <upstream-source> 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
Reply sent
to
Efraim Flashner <efraim <at> flashner.co.il>
:
You have taken responsibility.
(Tue, 16 Jan 2024 12:27:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Efraim Flashner <efraim <at> flashner.co.il>
:
bug acknowledged by developer.
(Tue, 16 Jan 2024 12:27:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 68346-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Sun, Jan 14, 2024 at 12:54:27PM +0000, David Elsing wrote:
> Hello,
>
> Efraim Flashner <efraim <at> flashner.co.il> 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:
I still think I like sort better, but it definitely doesn't do as good a
job of taking care of the #f case as your code does. I incorporated
your changes and pushed them.
--
Efraim Flashner <efraim <at> flashner.co.il> רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[signature.asc (application/pgp-signature, inline)]
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 14 Feb 2024 12:24:11 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 186 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.