cran.scm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
  3. ;;; Copyright © 2015, 2017, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
  4. ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
  5. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix scripts import cran)
  22. #:use-module (guix ui)
  23. #:use-module (guix utils)
  24. #:use-module (guix scripts)
  25. #:use-module (guix import cran)
  26. #:use-module (guix import utils)
  27. #:use-module (guix scripts import)
  28. #:use-module (srfi srfi-1)
  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-cran))
  34. ;;;
  35. ;;; Command-line options.
  36. ;;;
  37. (define %default-options
  38. '())
  39. (define (show-help)
  40. (display (G_ "Usage: guix import cran PACKAGE-NAME
  41. Import and convert the CRAN package for PACKAGE-NAME.\n"))
  42. (display (G_ "
  43. -a, --archive=ARCHIVE specify the archive repository"))
  44. (display (G_ "
  45. -h, --help display this help and exit"))
  46. (display (G_ "
  47. -r, --recursive import packages recursively"))
  48. (display (G_ "
  49. -s, --style=STYLE choose output style, either specification or variable"))
  50. (display (G_ "
  51. -V, --version display version information and exit"))
  52. (newline)
  53. (show-bug-report-information))
  54. (define %options
  55. ;; Specification of the command-line options.
  56. (cons* (option '(#\h "help") #f #f
  57. (lambda args
  58. (show-help)
  59. (exit 0)))
  60. (option '(#\V "version") #f #f
  61. (lambda args
  62. (show-version-and-exit "guix import cran")))
  63. (option '(#\a "archive") #t #f
  64. (lambda (opt name arg result)
  65. (alist-cons 'repo (string->symbol arg)
  66. (alist-delete 'repo result))))
  67. (option '(#\s "style") #t #f
  68. (lambda (opt name arg result)
  69. (alist-cons 'style (string->symbol arg)
  70. (alist-delete 'style result))))
  71. (option '(#\r "recursive") #f #f
  72. (lambda (opt name arg result)
  73. (alist-cons 'recursive #t result)))
  74. %standard-import-options))
  75. ;;;
  76. ;;; Entry point.
  77. ;;;
  78. (define (guix-import-cran . args)
  79. (define (parse-options)
  80. ;; Return the alist of option values.
  81. (parse-command-line args %options (list %default-options)
  82. #:build-options? #f))
  83. (let* ((opts (parse-options))
  84. (args (filter-map (match-lambda
  85. (('argument . value)
  86. value)
  87. (_ #f))
  88. (reverse opts))))
  89. (parameterize ((%input-style (assoc-ref opts 'style)))
  90. (match args
  91. ((spec)
  92. (let ((name version (package-name->name+version spec)))
  93. (if (assoc-ref opts 'recursive)
  94. ;; Recursive import
  95. (with-error-handling
  96. (map package->definition
  97. (filter identity
  98. (cran-recursive-import name
  99. #:version version
  100. #:repo (or (assoc-ref opts 'repo) 'cran)))))
  101. ;; Single import
  102. (let ((sexp (cran->guix-package name
  103. #:version version
  104. #:repo (or (assoc-ref opts 'repo) 'cran))))
  105. (unless sexp
  106. (leave (G_ "failed to download description for package '~a'~%")
  107. name))
  108. sexp))))
  109. (()
  110. (leave (G_ "too few arguments~%")))
  111. ((many ...)
  112. (leave (G_ "too many arguments~%")))))))