upstream: Define 'url-predicate' and use it.

* guix/upstream.scm (url-predicate): New procedure.
(url-prefix-predicate): Define in terms of 'url-predicate'.
* guix/import/cpan.scm (cpan-package?): Use 'url-predicate'.
* guix/import/cran.scm (cran-package?)
(bioconductor-package?)
(bioconductor-data-package?)
(bioconductor-experiment-package?): Likewise.
* guix/import/crate.scm (crate-package?): Likewise.
* guix/import/elpa.scm (package-from-gnu.org?): Likewise.
* guix/import/hackage.scm (hackage-package?): Likewise.
* guix/import/pypi.scm (pypi-package?): Likewise.
* guix/import/gem.scm (gem-package?): Use 'url-prefix-predicate'.
This commit is contained in:
Ludovic Courtès 2020-07-03 22:45:21 +02:00
parent 37c3e0bbaf
commit 00290e7365
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
8 changed files with 49 additions and 121 deletions

View File

@ -316,25 +316,13 @@ in RELEASE, a <cpan-release> record."
(let ((release (cpan-fetch (module->name module-name)))) (let ((release (cpan-fetch (module->name module-name))))
(and=> release cpan-module->sexp))) (and=> release cpan-module->sexp)))
(define (cpan-package? package) (define cpan-package?
"Return #t if PACKAGE is a package from CPAN." (let ((cpan-rx (make-regexp (string-append "("
(define cpan-url? "mirror://cpan" "|"
(let ((cpan-rx (make-regexp (string-append "(" "https?://www.cpan.org" "|"
"mirror://cpan" "|" "https?://cpan.metacpan.org"
"https?://www.cpan.org" "|" ")"))))
"https?://cpan.metacpan.org" (url-predicate (cut regexp-exec cpan-rx <>))))
")"))))
(lambda (url)
(regexp-exec cpan-rx url))))
(let ((source-url (and=> (package-source package) origin-uri))
(fetch-method (and=> (package-source package) origin-method)))
(and (eq? fetch-method url-fetch)
(match source-url
((? string?)
(cpan-url? source-url))
((source-url ...)
(any cpan-url? source-url))))))
(define (latest-release package) (define (latest-release package)
"Return an <upstream-source> for the latest release of PACKAGE." "Return an <upstream-source> for the latest release of PACKAGE."

View File

@ -661,12 +661,7 @@ s-expression corresponding to that package, or #f on failure."
;; Check if the upstream name can be extracted from package uri. ;; Check if the upstream name can be extracted from package uri.
(package->upstream-name package) (package->upstream-name package)
;; Check if package uri(s) are prefixed by "mirror://cran". ;; Check if package uri(s) are prefixed by "mirror://cran".
(match (and=> (package-source package) origin-uri) ((url-predicate (cut string-prefix? "mirror://cran" <>)) package)))
((? string? uri)
(string-prefix? "mirror://cran" uri))
((? list? uris)
(any (cut string-prefix? "mirror://cran" <>) uris))
(_ #f))))
(define (bioconductor-package? package) (define (bioconductor-package? package)
"Return true if PACKAGE is an R package from Bioconductor." "Return true if PACKAGE is an R package from Bioconductor."
@ -680,12 +675,7 @@ s-expression corresponding to that package, or #f on failure."
;; Experiment packages are in a separate repository. ;; Experiment packages are in a separate repository.
(not (string-contains uri "/data/experiment/")))))) (not (string-contains uri "/data/experiment/"))))))
(and (string-prefix? "r-" (package-name package)) (and (string-prefix? "r-" (package-name package))
(match (and=> (package-source package) origin-uri) ((url-predicate predicate) package))))
((? string? uri)
(predicate uri))
((? list? uris)
(any predicate uris))
(_ #f)))))
(define (bioconductor-data-package? package) (define (bioconductor-data-package? package)
"Return true if PACKAGE is an R data package from Bioconductor." "Return true if PACKAGE is an R data package from Bioconductor."
@ -693,12 +683,7 @@ s-expression corresponding to that package, or #f on failure."
(and (string-prefix? "https://bioconductor.org" uri) (and (string-prefix? "https://bioconductor.org" uri)
(string-contains uri "/data/annotation/"))))) (string-contains uri "/data/annotation/")))))
(and (string-prefix? "r-" (package-name package)) (and (string-prefix? "r-" (package-name package))
(match (and=> (package-source package) origin-uri) ((url-predicate predicate) package))))
((? string? uri)
(predicate uri))
((? list? uris)
(any predicate uris))
(_ #f)))))
(define (bioconductor-experiment-package? package) (define (bioconductor-experiment-package? package)
"Return true if PACKAGE is an R experiment package from Bioconductor." "Return true if PACKAGE is an R experiment package from Bioconductor."
@ -706,12 +691,7 @@ s-expression corresponding to that package, or #f on failure."
(and (string-prefix? "https://bioconductor.org" uri) (and (string-prefix? "https://bioconductor.org" uri)
(string-contains uri "/data/experiment/"))))) (string-contains uri "/data/experiment/")))))
(and (string-prefix? "r-" (package-name package)) (and (string-prefix? "r-" (package-name package))
(match (and=> (package-source package) origin-uri) ((url-predicate predicate) package))))
((? string? uri)
(predicate uri))
((? list? uris)
(any predicate uris))
(_ #f)))))
(define %cran-updater (define %cran-updater
(upstream-updater (upstream-updater

View File

@ -262,16 +262,8 @@ latest version of CRATE-NAME."
;;; Updater ;;; Updater
;;; ;;;
(define (crate-package? package) (define crate-package?
"Return true if PACKAGE is a Rust crate from crates.io." (url-predicate crate-url?))
(let ((source-url (and=> (package-source package) origin-uri))
(fetch-method (and=> (package-source package) origin-method)))
(and (eq? fetch-method download:url-fetch)
(match source-url
((? string?)
(crate-url? source-url))
((source-url ...)
(any crate-url? source-url))))))
(define (latest-release package) (define (latest-release package)
"Return an <upstream-source> for the latest release of PACKAGE." "Return an <upstream-source> for the latest release of PACKAGE."

View File

@ -281,13 +281,11 @@ type '<elpa-package>'."
(urls (list url)) (urls (list url))
(signature-urls (list (string-append url ".sig")))))) (signature-urls (list (string-append url ".sig"))))))
(define (package-from-gnu.org? package) (define package-from-gnu.org?
"Return true if PACKAGE is from elpa.gnu.org." (url-predicate (lambda (url)
(match (and=> (package-source package) origin-uri) (let ((uri (string->uri url)))
((? string? uri) (and uri
(let ((uri (string->uri uri))) (string=? (uri-host uri) "elpa.gnu.org"))))))
(and uri (string=? (uri-host uri) "elpa.gnu.org"))))
(_ #f)))
(define %elpa-updater (define %elpa-updater
;; The ELPA updater. We restrict it to packages hosted on elpa.gnu.org ;; The ELPA updater. We restrict it to packages hosted on elpa.gnu.org

View File

@ -166,20 +166,8 @@ package on RubyGems."
((or "Apache License, Version 2.0" "Apache 2.0") license:asl2.0) ((or "Apache License, Version 2.0" "Apache 2.0") license:asl2.0)
(_ #f))) (_ #f)))
(define (gem-package? package) (define gem-package?
"Return true if PACKAGE is a gem package from RubyGems." (url-prefix-predicate "https://rubygems.org/downloads/"))
(define (rubygems-url? url)
(string-prefix? "https://rubygems.org/downloads/" url))
(let ((source-url (and=> (package-source package) origin-uri))
(fetch-method (and=> (package-source package) origin-method)))
(and (eq? fetch-method download:url-fetch)
(match source-url
((? string?)
(rubygems-url? source-url))
((source-url ...)
(any rubygems-url? source-url))))))
(define (latest-release package) (define (latest-release package)
"Return an <upstream-source> for the latest release of PACKAGE." "Return an <upstream-source> for the latest release of PACKAGE."

View File

@ -346,22 +346,9 @@ respectively."
(cons name args))) (cons name args)))
#:guix-name hackage-name->package-name)) #:guix-name hackage-name->package-name))
(define (hackage-package? package) (define hackage-package?
"Return #t if PACKAGE is a Haskell package from Hackage." (let ((hackage-rx (make-regexp "https?://hackage.haskell.org")))
(url-predicate (cut regexp-exec hackage-rx <>))))
(define haskell-url?
(let ((hackage-rx (make-regexp "https?://hackage.haskell.org")))
(lambda (url)
(regexp-exec hackage-rx url))))
(let ((source-url (and=> (package-source package) origin-uri))
(fetch-method (and=> (package-source package) origin-method)))
(and (eq? fetch-method url-fetch)
(match source-url
((? string?)
(haskell-url? source-url))
((source-url ...)
(any haskell-url? source-url))))))
(define (latest-release package) (define (latest-release package)
"Return an <upstream-source> for the latest release of PACKAGE." "Return an <upstream-source> for the latest release of PACKAGE."

View File

@ -510,23 +510,13 @@ VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
("MPL 2.0" license:mpl2.0) ("MPL 2.0" license:mpl2.0)
(_ #f))) (_ #f)))
(define (pypi-package? package) (define pypi-package?
"Return true if PACKAGE is a Python package from PyPI." (url-predicate
(lambda (url)
(define (pypi-url? url) (or (string-prefix? "https://pypi.org/" url)
(or (string-prefix? "https://pypi.org/" url) (string-prefix? "https://pypi.python.org/" url)
(string-prefix? "https://pypi.python.org/" url) (string-prefix? "https://pypi.org/packages" url)
(string-prefix? "https://pypi.org/packages" url) (string-prefix? "https://files.pythonhosted.org/packages" url)))))
(string-prefix? "https://files.pythonhosted.org/packages" url)))
(let ((source-url (and=> (package-source package) origin-uri))
(fetch-method (and=> (package-source package) origin-method)))
(and (eq? fetch-method download:url-fetch)
(match source-url
((? string?)
(pypi-url? source-url))
((source-url ...)
(any pypi-url? source-url))))))
(define (latest-release package) (define (latest-release package)
"Return an <upstream-source> for the latest release of PACKAGE." "Return an <upstream-source> for the latest release of PACKAGE."

View File

@ -51,6 +51,7 @@
upstream-source-archive-types upstream-source-archive-types
upstream-source-input-changes upstream-source-input-changes
url-predicate
url-prefix-predicate url-prefix-predicate
coalesce-sources coalesce-sources
@ -161,23 +162,27 @@ S-expression PACKAGE-SEXP."
current-propagated new-propagated)))))) current-propagated new-propagated))))))
(_ '()))) (_ '())))
(define* (url-predicate matching-url?)
"Return a predicate that returns true when passed a package whose source is
an <origin> with the URL-FETCH method, and one of its URLs passes
MATCHING-URL?."
(lambda (package)
(match (package-source package)
((? origin? origin)
(and (eq? (origin-method origin) url-fetch)
(match (origin-uri origin)
((? string? url)
(matching-url? url))
(((? string? urls) ...)
(any matching-url? urls))
(_
#f))))
(_ #f))))
(define (url-prefix-predicate prefix) (define (url-prefix-predicate prefix)
"Return a predicate that returns true when passed a package where one of its "Return a predicate that returns true when passed a package where one of its
source URLs starts with PREFIX." source URLs starts with PREFIX."
(lambda (package) (url-predicate (cut string-prefix? prefix <>)))
(define matching-uri?
(match-lambda
((? string? uri)
(string-prefix? prefix uri))
(_
#f)))
(match (package-source package)
((? origin? origin)
(match (origin-uri origin)
((? matching-uri?) #t)
(_ #f)))
(_ #f))))
(define (upstream-source-archive-types release) (define (upstream-source-archive-types release)
"Return the available types of archives for RELEASE---a list of strings such "Return the available types of archives for RELEASE---a list of strings such