guix: import: Don't import yanked rust crates.

* guix/import/crate.scm (<crate-version>): Add yanked? field.
(crate->guix-package)[find-crate-version]: Remove versions which have
been yanked.
* tests/crate.scm: Adjust tests for new yanked? field.
This commit is contained in:
Efraim Flashner 2023-10-09 15:15:46 +03:00
parent 6d4f4e916a
commit 742554f9b9
No known key found for this signature in database
GPG key ID: 41AAE7DCCA3D8351
2 changed files with 34 additions and 15 deletions

View file

@ -5,6 +5,7 @@
;;; Copyright © 2021 Nicolas Goaziou <mail@nicolasgoaziou.fr> ;;; Copyright © 2021 Nicolas Goaziou <mail@nicolasgoaziou.fr>
;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com> ;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com>
;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com> ;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -82,6 +83,7 @@ (define-json-mapping <crate-version> make-crate-version crate-version?
(match-lambda (match-lambda
('null #f) ('null #f)
((? string? str) str))) ((? string? str) str)))
(yanked? crate-version-yanked? "yanked") ;boolean
(links crate-version-links)) ;alist (links crate-version-links)) ;alist
;; Crate dependency. Each dependency (each edge in the graph) is annotated as ;; Crate dependency. Each dependency (each edge in the graph) is annotated as
@ -255,13 +257,16 @@ (define (find-package-version name range)
(and (not (null-list? versions)) (and (not (null-list? versions))
(semver->string (last versions))))) (semver->string (last versions)))))
;; find the highest version of a crate that fulfills the semver <range> ;; Find the highest version of a crate that fulfills the semver <range>
;; and hasn't been yanked.
(define (find-crate-version crate range) (define (find-crate-version crate range)
(let* ((semver-range (string->semver-range range)) (let* ((semver-range (string->semver-range range))
(versions (versions
(sort (sort
(filter (lambda (entry) (filter (lambda (entry)
(semver-range-contains? semver-range (first entry))) (and
(not (crate-version-yanked? (second entry)))
(semver-range-contains? semver-range (first entry))))
(map (lambda (ver) (map (lambda (ver)
(list (string->semver (crate-version-number ver)) (list (string->semver (crate-version-number ver))
ver)) ver))

View file

@ -3,6 +3,7 @@
;;; Copyright © 2016 David Craven <david@craven.ch> ;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net> ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -76,21 +77,24 @@ (define test-foo-crate
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/foo/0.8.1/dependencies\" \"dependencies\": \"/api/v1/crates/foo/0.8.1/dependencies\"
} },
\"yanked\": false
}, },
{ \"id\": 234212, { \"id\": 234212,
\"num\": \"1.0.0\", \"num\": \"1.0.0\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\"
} },
\"yanked\": false
}, },
{ \"id\": 234214, { \"id\": 234214,
\"num\": \"1.0.3\", \"num\": \"1.0.3\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/foo/1.0.3/dependencies\" \"dependencies\": \"/api/v1/crates/foo/1.0.3/dependencies\"
} },
\"yanked\": false
} }
] ]
} }
@ -123,14 +127,16 @@ (define test-root-crate
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/root/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/root/1.0.0/dependencies\"
} },
\"yanked\": false
}, },
{ \"id\": 234242, { \"id\": 234242,
\"num\": \"1.0.4\", \"num\": \"1.0.4\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/root/1.0.4/dependencies\" \"dependencies\": \"/api/v1/crates/root/1.0.4/dependencies\"
} },
\"yanked\": false
} }
] ]
} }
@ -178,21 +184,24 @@ (define test-intermediate-a-crate
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-a/1.0.40/dependencies\" \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.40/dependencies\"
} },
\"yanked\": false
}, },
{ \"id\": 234250, { \"id\": 234250,
\"num\": \"1.0.42\", \"num\": \"1.0.42\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-a/1.0.42/dependencies\" \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.42/dependencies\"
} },
\"yanked\": false
}, },
{ \"id\": 234252, { \"id\": 234252,
\"num\": \"1.1.0-alpha.1\", \"num\": \"1.1.0-alpha.1\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-a/1.1.0-alpha.1/dependencies\" \"dependencies\": \"/api/v1/crates/intermediate-a/1.1.0-alpha.1/dependencies\"
} },
\"yanked\": false
} }
] ]
} }
@ -235,7 +244,8 @@ (define test-intermediate-b-crate
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-b/1.2.3/dependencies\" \"dependencies\": \"/api/v1/crates/intermediate-b/1.2.3/dependencies\"
} },
\"yanked\": false
} }
] ]
} }
@ -268,14 +278,16 @@ (define test-leaf-alice-crate
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/leaf-alice/0.7.3/dependencies\" \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.3/dependencies\"
} },
\"yanked\": false
}, },
{ \"id\": 234272, { \"id\": 234272,
\"num\": \"0.7.5\", \"num\": \"0.7.5\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/leaf-alice/0.7.5/dependencies\" \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.5/dependencies\"
} },
\"yanked\": false
} }
] ]
} }
@ -302,7 +314,8 @@ (define test-leaf-bob-crate
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/leaf-bob/3.0.1/dependencies\" \"dependencies\": \"/api/v1/crates/leaf-bob/3.0.1/dependencies\"
} },
\"yanked\": false
} }
] ]
} }
@ -597,7 +610,8 @@ (define test-doctool-crate
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/doctool/2.2.2/dependencies\" \"dependencies\": \"/api/v1/crates/doctool/2.2.2/dependencies\"
} },
\"yanked\": false
} }
] ]
} }