diff options
| author | Cyril Roelandt <tipecaml@gmail.com> | 2015-11-03 22:38:49 +0100 |
|---|---|---|
| committer | Cyril Roelandt <tipecaml@gmail.com> | 2015-11-03 23:41:25 +0100 |
| commit | bab020d7ca50e4153cf24832d119389a37fa8f63 (patch) | |
| tree | 2d5f2527027d729b281c91983b1bb9feb2ccc7a5 | |
| parent | 465b61fcd638e9dffe2cdd6d52f36bd692fab9a9 (diff) | |
import: pypi: add updater
* guix/import/pypi.scm (guix-package->pypi-name,
latest-release): New procedures.
(%pypi-updater): New variable.
* guix/scripts/refresh.scm (%updaters): Add %PYPI-UPDATER.
* doc/guix.texi (Invoking guix refresh): Mention PyPI
| -rw-r--r-- | doc/guix.texi | 2 | ||||
| -rw-r--r-- | guix/import/pypi.scm | 50 | ||||
| -rw-r--r-- | guix/scripts/refresh.scm | 4 |
3 files changed, 54 insertions, 2 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 996192c0eac..23f9c3c0a97 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -4291,6 +4291,8 @@ the updater for GNU packages; | |||
| 4291 | the updater for @uref{http://elpa.gnu.org/, ELPA} packages; | 4291 | the updater for @uref{http://elpa.gnu.org/, ELPA} packages; |
| 4292 | @item cran | 4292 | @item cran |
| 4293 | the updater fro @uref{http://cran.r-project.org/, CRAN} packages. | 4293 | the updater fro @uref{http://cran.r-project.org/, CRAN} packages. |
| 4294 | @item pypi | ||
| 4295 | the updater fro @uref{https://pypi.python.org, PyPI} packages. | ||
| 4294 | @end table | 4296 | @end table |
| 4295 | 4297 | ||
| 4296 | For instance, the following commands only checks for updates of Emacs | 4298 | For instance, the following commands only checks for updates of Emacs |
diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm index 647ef615e0f..f1988a7186e 100644 --- a/guix/import/pypi.scm +++ b/guix/import/pypi.scm | |||
| @@ -30,12 +30,16 @@ | |||
| 30 | #:use-module (guix ui) | 30 | #:use-module (guix ui) |
| 31 | #:use-module (guix utils) | 31 | #:use-module (guix utils) |
| 32 | #:use-module (guix import utils) | 32 | #:use-module (guix import utils) |
| 33 | #:use-module ((guix download) #:prefix download:) | ||
| 33 | #:use-module (guix import json) | 34 | #:use-module (guix import json) |
| 34 | #:use-module (guix packages) | 35 | #:use-module (guix packages) |
| 36 | #:use-module (guix upstream) | ||
| 35 | #:use-module (guix licenses) | 37 | #:use-module (guix licenses) |
| 36 | #:use-module (guix build-system python) | 38 | #:use-module (guix build-system python) |
| 39 | #:use-module (gnu packages) | ||
| 37 | #:use-module (gnu packages python) | 40 | #:use-module (gnu packages python) |
| 38 | #:export (pypi->guix-package)) | 41 | #:export (pypi->guix-package |
| 42 | %pypi-updater)) | ||
| 39 | 43 | ||
| 40 | (define (pypi-fetch name) | 44 | (define (pypi-fetch name) |
| 41 | "Return an alist representation of the PyPI metadata for the package NAME, | 45 | "Return an alist representation of the PyPI metadata for the package NAME, |
| @@ -60,6 +64,16 @@ package." | |||
| 60 | (snake-case name) | 64 | (snake-case name) |
| 61 | (string-append "python-" (snake-case name)))) | 65 | (string-append "python-" (snake-case name)))) |
| 62 | 66 | ||
| 67 | (define (guix-package->pypi-name package) | ||
| 68 | "Given a Python PACKAGE built from pypi.python.org, return the name of the | ||
| 69 | package on PyPI." | ||
| 70 | (let ((source-url (and=> (package-source package) origin-uri))) | ||
| 71 | ;; The URL has the form: | ||
| 72 | ;; 'https://pypi.python.org/packages/source/' + | ||
| 73 | ;; first letter of the package name + | ||
| 74 | ;; '/' + package name + '/' + ... | ||
| 75 | (substring source-url 42 (string-rindex source-url #\/)))) | ||
| 76 | |||
| 63 | (define (maybe-inputs package-inputs) | 77 | (define (maybe-inputs package-inputs) |
| 64 | "Given a list of PACKAGE-INPUTS, tries to generate the 'inputs' field of a | 78 | "Given a list of PACKAGE-INPUTS, tries to generate the 'inputs' field of a |
| 65 | package definition." | 79 | package definition." |
| @@ -190,3 +204,37 @@ VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." | |||
| 190 | (license (string->license (assoc-ref* package "info" "license")))) | 204 | (license (string->license (assoc-ref* package "info" "license")))) |
| 191 | (make-pypi-sexp name version release home-page synopsis | 205 | (make-pypi-sexp name version release home-page synopsis |
| 192 | description license))))) | 206 | description license))))) |
| 207 | |||
| 208 | (define (pypi-package? package) | ||
| 209 | "Return true if PACKAGE is a Python package from PyPI." | ||
| 210 | |||
| 211 | (define (pypi-url? url) | ||
| 212 | (string-prefix? "https://pypi.python.org/" url)) | ||
| 213 | |||
| 214 | (let ((source-url (and=> (package-source package) origin-uri)) | ||
| 215 | (fetch-method (and=> (package-source package) origin-method))) | ||
| 216 | (and (eq? fetch-method download:url-fetch) | ||
| 217 | (match source-url | ||
| 218 | ((? string?) | ||
| 219 | (pypi-url? source-url)) | ||
| 220 | ((source-url ...) | ||
| 221 | (any pypi-url? source-url)))))) | ||
| 222 | |||
| 223 | (define (latest-release guix-package) | ||
| 224 | "Return an <upstream-source> for the latest release of GUIX-PACKAGE." | ||
| 225 | (let* ((pypi-name (guix-package->pypi-name | ||
| 226 | (specification->package guix-package))) | ||
| 227 | (metadata (pypi-fetch pypi-name)) | ||
| 228 | (version (assoc-ref* metadata "info" "version")) | ||
| 229 | (url (assoc-ref (latest-source-release metadata) "url"))) | ||
| 230 | (upstream-source | ||
| 231 | (package guix-package) | ||
| 232 | (version version) | ||
| 233 | (urls (list url))))) | ||
| 234 | |||
| 235 | (define %pypi-updater | ||
| 236 | (upstream-updater | ||
| 237 | (name 'pypi) | ||
| 238 | (description "Updater for PyPI packages") | ||
| 239 | (pred pypi-package?) | ||
| 240 | (latest latest-release))) | ||
diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm index 0df4121d0a8..3984a0bde10 100644 --- a/guix/scripts/refresh.scm +++ b/guix/scripts/refresh.scm | |||
| @@ -30,6 +30,7 @@ | |||
| 30 | #:use-module ((guix gnu-maintenance) #:select (%gnu-updater)) | 30 | #:use-module ((guix gnu-maintenance) #:select (%gnu-updater)) |
| 31 | #:use-module (guix import elpa) | 31 | #:use-module (guix import elpa) |
| 32 | #:use-module (guix import cran) | 32 | #:use-module (guix import cran) |
| 33 | #:use-module (guix import pypi) | ||
| 33 | #:use-module (guix gnupg) | 34 | #:use-module (guix gnupg) |
| 34 | #:use-module (gnu packages) | 35 | #:use-module (gnu packages) |
| 35 | #:use-module ((gnu packages commencement) #:select (%final-inputs)) | 36 | #:use-module ((gnu packages commencement) #:select (%final-inputs)) |
| @@ -152,7 +153,8 @@ specified with `--select'.\n")) | |||
| 152 | ;; List of "updaters" used by default. They are consulted in this order. | 153 | ;; List of "updaters" used by default. They are consulted in this order. |
| 153 | (list %gnu-updater | 154 | (list %gnu-updater |
| 154 | %elpa-updater | 155 | %elpa-updater |
| 155 | %cran-updater)) | 156 | %cran-updater |
| 157 | %pypi-updater)) | ||
| 156 | 158 | ||
| 157 | (define (lookup-updater name) | 159 | (define (lookup-updater name) |
| 158 | "Return the updater called NAME." | 160 | "Return the updater called NAME." |
