From: Ricardo Wurmus <rekado@elephly.net>
To: 27296@debbugs.gnu.org
Cc: Ricardo Wurmus <rekado@elephly.net>
Subject: bug#27296: [PATCH 35/35] guix: Add texlive importer.
Date: Fri, 9 Jun 2017 12:45:59 +0200 [thread overview]
Message-ID: <20170609104559.17416-35-rekado@elephly.net> (raw)
In-Reply-To: <20170609104559.17416-1-rekado@elephly.net>
* guix/import/texlive.scm: New file.
* guix/scripts/import/texlive.scm: New file.
* Makefile.am (MODULES): Add them.
* guix/scripts/import.scm (importers): Add texlive importer.
---
Makefile.am | 2 +
guix/import/texlive.scm | 181 ++++++++++++++++++++++++++++++++++++++++
guix/scripts/import.scm | 2 +-
guix/scripts/import/texlive.scm | 101 ++++++++++++++++++++++
4 files changed, 285 insertions(+), 1 deletion(-)
create mode 100644 guix/import/texlive.scm
create mode 100644 guix/scripts/import/texlive.scm
diff --git a/Makefile.am b/Makefile.am
index c10dffb44..df524e698 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -145,6 +145,7 @@ MODULES = \
guix/import/cran.scm \
guix/import/hackage.scm \
guix/import/elpa.scm \
+ guix/import/texlive.scm \
guix/scripts.scm \
guix/scripts/download.scm \
guix/scripts/perform-download.scm \
@@ -167,6 +168,7 @@ MODULES = \
guix/scripts/import/nix.scm \
guix/scripts/import/hackage.scm \
guix/scripts/import/elpa.scm \
+ guix/scripts/import/texlive.scm \
guix/scripts/environment.scm \
guix/scripts/publish.scm \
guix/scripts/edit.scm \
diff --git a/guix/import/texlive.scm b/guix/import/texlive.scm
new file mode 100644
index 000000000..ef3facf0d
--- /dev/null
+++ b/guix/import/texlive.scm
@@ -0,0 +1,181 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix import texlive)
+ #:use-module (ice-9 match)
+ #:use-module (sxml simple)
+ #:use-module (sxml xpath)
+ #:use-module (srfi srfi-11)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-34)
+ #:use-module (web uri)
+ #:use-module (guix http-client)
+ #:use-module (guix hash)
+ #:use-module (guix memoization)
+ #:use-module (guix store)
+ #:use-module (guix base32)
+ #:use-module (guix serialization)
+ #:use-module (guix svn-download)
+ #:use-module (guix import utils)
+ #:use-module (guix utils)
+ #:use-module (guix upstream)
+ #:use-module (guix packages)
+ #:use-module (gnu packages)
+ #:use-module (guix build-system texlive)
+ #:export (texlive->guix-package))
+
+;;; Commentary:
+;;;
+;;; Generate a package declaration template for the latest version of a
+;;; package on CTAN, using the XML output produced by the XML API to the CTAN
+;;; database at http://www.ctan.org/xml/1.2/
+;;;
+;;; Instead of taking the packages from CTAN, however, we fetch the sources
+;;; from the SVN repository of the Texlive project. We do this because CTAN
+;;; only keeps a single version of each package whereas we can access any
+;;; version via SVN. Unfortunately, this means that the importer is really
+;;; just a Texlive importer, not a generic CTAN importer.
+;;;
+;;; Code:
+
+(define string->license
+ (match-lambda
+ ("artistic2" 'gpl3+)
+ ("gpl" 'gpl3+)
+ ("gpl1" 'gpl1)
+ ("gpl1+" 'gpl1+)
+ ("gpl2" 'gpl2)
+ ("gpl2+" 'gpl2+)
+ ("gpl3" 'gpl3)
+ ("gpl3+" 'gpl3+)
+ ("lgpl2.1" 'lgpl2.1)
+ ("lgpl3" 'lgpl3)
+ ("knuth" 'knuth)
+ ("pd" 'public-domain)
+ ("bsd2" 'bsd-2)
+ ("bsd3" 'bsd-3)
+ ("bsd4" 'bsd-4)
+ ("opl" 'opl1.0+)
+ ("ofl" 'silofl1.1)
+ ("lppl" 'lppl)
+ ("lppl1" 'lppl1.0+) ; usually means "or later"
+ ("lppl1.2" 'lppl1.2+) ; usually means "or later"
+ ("lppl1.3" 'lppl1.3+) ; usually means "or later"
+ ("lppl1.3a" 'lppl1.3a)
+ ("lppl1.3b" 'lppl1.3b)
+ ("lppl1.3c" 'lppl1.3c)
+ ("cc-by-2" 'cc-by-2.0)
+ ("cc-by-3" 'cc-by-3.0)
+ ("cc-by-sa-2" 'cc-by-sa2.0)
+ ("cc-by-sa-3" 'cc-by-sa3.0)
+ ("mit" 'expat)
+ ("fdl" 'fdl1.3+)
+ ("gfl" 'gfl1.0)
+
+ ;; These are known non-free licenses
+ ("noinfo" 'unknown)
+ ("nosell" 'non-free)
+ ("shareware" 'non-free)
+ ("nosource" 'non-free)
+ ("nocommercial" 'non-free)
+ ("cc-by-nc-nd-1" 'non-free)
+ ("cc-by-nc-nd-2" 'non-free)
+ ("cc-by-nc-nd-2.5" 'non-free)
+ ("cc-by-nc-nd-3" 'non-free)
+ ("cc-by-nc-nd-4" 'non-free)
+ ((x) (string->license x))
+ ((lst ...) `(list ,@(map string->license lst)))
+ (_ #f)))
+
+(define (fetch-sxml name)
+ "Return an sxml representation of the package information contained in the
+XML description of the CTAN package or #f in case of failure."
+ ;; This API always returns the latest release of the module.
+ (let ((url (string-append "http://www.ctan.org/xml/1.2/pkg/" name)))
+ (guard (c ((http-get-error? c)
+ (format (current-error-port)
+ "error: failed to retrieve package information \
+from ~s: ~a (~s)~%"
+ (uri->string (http-get-error-uri c))
+ (http-get-error-code c)
+ (http-get-error-reason c))
+ #f))
+ (xml->sxml (http-fetch url)
+ #:trim-whitespace? #t))))
+
+(define (guix-name component name)
+ "Return a Guix package name for a given Texlive package NAME."
+ (string-append "texlive-" component "-"
+ (string-map (match-lambda
+ (#\_ #\-)
+ (#\. #\-)
+ (chr (char-downcase chr)))
+ name)))
+
+(define* (sxml->package sxml #:optional (component "latex"))
+ "Return the `package' s-expression for a Texlive package from the SXML
+expression describing it."
+ (define (sxml-value path)
+ (match ((sxpath path) sxml)
+ (() #f)
+ ((val) val)))
+ (let* ((id (sxml-value '(entry @ id *text*)))
+ (synopsis (sxml-value '(entry caption *text*)))
+ (version (or (sxml-value '(entry version @ number *text*))
+ (sxml-value '(entry version @ date *text*))))
+ (license (string->license (sxml-value '(entry license @ type *text*))))
+ (home-page (string-append "http://www.ctan.org/pkg/" id))
+ (ref (texlive-ref component id))
+ (checkout (with-store store (download-svn-to-store store ref))))
+ `(package
+ (name ,(guix-name component id))
+ (version ,version)
+ (source (origin
+ (method svn-fetch)
+ (uri (texlive-ref ,component ,id))
+ (sha256
+ (base32
+ ,(bytevector->nix-base32-string
+ (let-values (((port get-hash) (open-sha256-port)))
+ (write-file checkout port)
+ (force-output port)
+ (get-hash)))))))
+ (build-system texlive-build-system)
+ (arguments ,`(,'quote (#:tex-directory ,(string-join (list component id) "/"))))
+ (home-page ,home-page)
+ (synopsis ,synopsis)
+ (description ,(string-trim-both
+ (string-join
+ (map string-trim-both
+ (string-split
+ (beautify-description
+ (sxml->string (or (sxml-value '(entry description))
+ '())))
+ #\newline)))))
+ (license ,license))))
+
+(define texlive->guix-package
+ (memoize
+ (lambda* (package-name #:optional (component "latex"))
+ "Fetch the metadata for PACKAGE-NAME from REPO and return the `package'
+s-expression corresponding to that package, or #f on failure."
+ (and=> (fetch-sxml package-name)
+ (cut sxml->package <> component)))))
+
+;;; ctan.scm ends here
diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index 203cda804..9bba074e8 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -74,7 +74,7 @@ rather than \\n."
;;;
(define importers '("gnu" "nix" "pypi" "cpan" "hackage" "stackage" "elpa" "gem"
- "cran" "crate"))
+ "cran" "crate" "texlive"))
(define (resolve-importer name)
(let ((module (resolve-interface
diff --git a/guix/scripts/import/texlive.scm b/guix/scripts/import/texlive.scm
new file mode 100644
index 000000000..1cceee705
--- /dev/null
+++ b/guix/scripts/import/texlive.scm
@@ -0,0 +1,101 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix scripts import texlive)
+ #:use-module (guix ui)
+ #:use-module (guix utils)
+ #:use-module (guix scripts)
+ #:use-module (guix import texlive)
+ #:use-module (guix scripts import)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-11)
+ #:use-module (srfi srfi-37)
+ #:use-module (srfi srfi-41)
+ #:use-module (ice-9 match)
+ #:use-module (ice-9 format)
+ #:export (guix-import-texlive))
+
+\f
+;;;
+;;; Command-line options.
+;;;
+
+(define %default-options
+ '())
+
+(define (show-help)
+ (display (G_ "Usage: guix import texlive PACKAGE-NAME
+Import and convert the Texlive package for PACKAGE-NAME.\n"))
+ (display (G_ "
+ -a, --archive=ARCHIVE specify the archive repository"))
+ (display (G_ "
+ -h, --help display this help and exit"))
+ (display (G_ "
+ -V, --version display version information and exit"))
+ (newline)
+ (show-bug-report-information))
+
+(define %options
+ ;; Specification of the command-line options.
+ (cons* (option '(#\h "help") #f #f
+ (lambda args
+ (show-help)
+ (exit 0)))
+ (option '(#\V "version") #f #f
+ (lambda args
+ (show-version-and-exit "guix import texlive")))
+ (option '(#\a "archive") #t #f
+ (lambda (opt name arg result)
+ (alist-cons 'component arg
+ (alist-delete 'component result))))
+ %standard-import-options))
+
+\f
+;;;
+;;; Entry point.
+;;;
+
+(define (guix-import-texlive . args)
+ (define (parse-options)
+ ;; Return the alist of option values.
+ (args-fold* args %options
+ (lambda (opt name arg result)
+ (leave (G_ "~A: unrecognized option~%") name))
+ (lambda (arg result)
+ (alist-cons 'argument arg result))
+ %default-options))
+
+ (let* ((opts (parse-options))
+ (args (filter-map (match-lambda
+ (('argument . value)
+ value)
+ (_ #f))
+ (reverse opts))))
+ (match args
+ ((package-name)
+ (let ((sexp (texlive->guix-package package-name
+ (or (assoc-ref opts 'component)
+ "latex"))))
+ (unless sexp
+ (leave (G_ "failed to download description for package '~a'~%")
+ package-name))
+ sexp))
+ (()
+ (leave (G_ "too few arguments~%")))
+ ((many ...)
+ (leave (G_ "too many arguments~%"))))))
--
2.12.2
next prev parent reply other threads:[~2017-06-09 10:48 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-09 10:42 bug#27296: Modular Texlive Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 01/35] guix: Add download-svn-to-store Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 02/35] guix: Add common TeX and LaTeX licenses Ricardo Wurmus
2017-06-09 14:45 ` Ludovic Courtès
2017-06-10 2:15 ` Arun Isaac
2017-06-09 10:45 ` bug#27296: [PATCH 03/35] gnu: Add texlive-dvips Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 04/35] gnu: Add texlive-generic-unicode-data Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 05/35] gnu: Add texlive-generic-dehyph-exptl Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 06/35] gnu: Add texlive-generic-tex-ini-files Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 07/35] gnu: Add texlive-generic-hyph-utf8 Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 08/35] gnu: Add texlive-metafont-base Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 09/35] gnu: Add texlive-fonts-cm Ricardo Wurmus
2017-06-09 14:41 ` Ludovic Courtès
2017-06-09 15:00 ` Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 10/35] gnu: Add texlive-fonts-knuth-lib Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 11/35] gnu: Add texlive-fonts-latex Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 12/35] gnu: Add texlive-tex-plain Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 13/35] gnu: Add texlive-latex-base Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 14/35] build-system: Add 'texlive-build-system' Ricardo Wurmus
2017-06-09 14:50 ` Ludovic Courtès
2017-06-14 7:24 ` [bug#27296] " Ricardo Wurmus
2017-06-14 7:41 ` Ludovic Courtès
2017-06-09 10:45 ` bug#27296: [PATCH 15/35] gnu: Add texlive-latex-filecontents Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 16/35] gnu: Add texlive-generic-ifxetex Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 17/35] gnu: Add texlive-latex-fancyvrb Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 18/35] gnu: Add texlive-latex-graphics Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 19/35] gnu: Add texlive-latex-xcolor Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 20/35] gnu: Add texlive-latex-hyperref Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 21/35] gnu: Add texlive-latex-oberdiek Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 22/35] gnu: Add texlive-latex-tools Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 23/35] gnu: Add texlive-latex-url Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 24/35] gnu: Add texlive-latex-l3kernel Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 25/35] gnu: Add texlive-latex-l3packages Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 26/35] gnu: Add texlive-latex-fontspec Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 27/35] gnu: Add texlive-luatex-lualibs Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 28/35] gnu: Add texlive-latex-amsmath Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 29/35] gnu: Add texlive-latex-amscls Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 30/35] gnu: Add texlive-latex-babel Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 31/35] gnu: texlive-latex-cyrillic Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 32/35] gnu: Add texlive-latex-psnfss Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 33/35] gnu: Add texlive-union Ricardo Wurmus
2017-06-09 14:57 ` Ludovic Courtès
2017-06-09 15:06 ` Ricardo Wurmus
2017-06-09 15:12 ` Ludovic Courtès
2017-06-09 15:51 ` Ricardo Wurmus
2017-06-09 10:45 ` bug#27296: [PATCH 34/35] gnu: Add texlive-tiny Ricardo Wurmus
2017-06-09 10:45 ` Ricardo Wurmus [this message]
2017-06-09 15:05 ` bug#27296: [PATCH 35/35] guix: Add texlive importer Ludovic Courtès
2017-06-15 15:01 ` [bug#27296] " Ricardo Wurmus
2017-06-16 15:06 ` Ludovic Courtès
2017-06-16 16:12 ` Ricardo Wurmus
2017-06-09 14:38 ` bug#27296: [PATCH 01/35] guix: Add download-svn-to-store Ludovic Courtès
2017-06-15 15:04 ` bug#27296: Modular Texlive Ricardo Wurmus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170609104559.17416-35-rekado@elephly.net \
--to=rekado@elephly.net \
--cc=27296@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).