1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
4 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (guix scripts import pypi)
22 #:use-module (guix ui)
23 #:use-module (guix utils)
24 #:use-module (guix scripts)
25 #:use-module (guix import pypi)
26 #:use-module (guix scripts import)
27 #:use-module (srfi srfi-1)
28 #:use-module (srfi srfi-11)
29 #:use-module (srfi srfi-37)
30 #:use-module (srfi srfi-71)
31 #:use-module (ice-9 match)
32 #:use-module (ice-9 format)
33 #:export (guix-import-pypi))
37 ;;; Command-line options.
40 (define %default-options
44 (display (G_ "Usage: guix import pypi PACKAGE-NAME
45 Import and convert the PyPI package for PACKAGE-NAME.\n"))
47 -h, --help display this help and exit"))
49 -r, --recursive import packages recursively"))
51 -V, --version display version information and exit"))
53 (show-bug-report-information))
56 ;; Specification of the command-line options.
57 (cons* (option '(#\h "help") #f #f
61 (option '(#\V "version") #f #f
63 (show-version-and-exit "guix import pypi")))
64 (option '(#\r "recursive") #f #f
65 (lambda (opt name arg result)
66 (alist-cons 'recursive #t result)))
67 %standard-import-options))
74 (define (guix-import-pypi . args)
75 (define (parse-options)
76 ;; Return the alist of option values.
77 (parse-command-line args %options (list %default-options)
80 (let* ((opts (parse-options))
81 (args (filter-map (match-lambda
88 (let ((name version (package-name->name+version spec)))
89 (if (assoc-ref opts 'recursive)
92 ((and ('package ('name name) . rest) pkg)
93 `(define-public ,(string->symbol name)
96 (pypi-recursive-import name version))
98 (let ((sexp (pypi->guix-package name #:version version)))
100 (leave (G_ "failed to download meta-data for package '~a'~%")
104 (leave (G_ "too few arguments~%")))
106 (leave (G_ "too many arguments~%"))))))