From 1b3e968512ebbccf02d00c52f7e089156946f445 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 27 Sep 2014 10:16:23 -0400 Subject: import: Add PyPI importer. * guix/snix.scm: Delete. * guix/import/snix.scm: New file. * guix/import/pypi.scm: New file. * guix/import/utils.scm: New file. * guix/scripts/import/nix.scm: New file. * guix/scripts/import/pypi.scm: New file. * tests/pypi.scm: New file. * tests/snix.scm: Import (guix import snix) module. * guix/scripts/import.scm (%default-options, %options): Delete. (%standard-import-options, importers): New variables. (show-help): List importers. (guix-import): Factor out Nix-specific logic. Delegate to correct importer based upon first argument. * configure.ac (HAVE_GUILE_JSON): New conditional. * Makefile.am (MODULES): Add new files and remove 'guix/snix.scm'. (SCM_TESTS): Add 'tests/pypi.scm' if guile-json is installed. --- guix/scripts/import.scm | 85 +++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 46 deletions(-) (limited to 'guix/scripts/import.scm') diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm index 6f75017d6e..e9576bad8c 100644 --- a/guix/scripts/import.scm +++ b/guix/scripts/import.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013 Ludovic Courtès +;;; Copyright © 2014 David Thompson ;;; ;;; This file is part of GNU Guix. ;;; @@ -18,15 +19,16 @@ (define-module (guix scripts import) #:use-module (guix ui) - #:use-module (guix snix) #:use-module (guix utils) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) + #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 pretty-print) - #:export (guix-import)) + #:export (%standard-import-options + guix-import)) ;;; @@ -61,15 +63,30 @@ rather than \\n." ;;; -;;; Command-line options. +;;; Command line options. ;;; -(define %default-options - '()) +(define %standard-import-options '()) + + +;;; +;;; Entry point. +;;; + +(define importers '("nix" "pypi")) + +(define (resolve-importer name) + (let ((module (resolve-interface + `(guix scripts import ,(string->symbol name)))) + (proc (string->symbol (string-append "guix-import-" name)))) + (module-ref module proc))) (define (show-help) - (display (_ "Usage: guix import NIXPKGS ATTRIBUTE -Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n")) + (display (_ "Usage: guix import IMPORTER ARGS ... +Run IMPORTER with ARGS.\n")) + (newline) + (display (_ "IMPORTER must be one of the importers listed below:\n")) + (format #t "~{ ~a~%~}" importers) (display (_ " -h, --help display this help and exit")) (display (_ " @@ -77,43 +94,19 @@ Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n")) (newline) (show-bug-report-information)) -(define %options - ;; Specification of the command-line options. - (list (option '(#\h "help") #f #f - (lambda args - (show-help) - (exit 0))) - (option '(#\V "version") #f #f - (lambda args - (show-version-and-exit "guix import"))))) - - -;;; -;;; Entry point. -;;; - (define (guix-import . args) - (define (parse-options) - ;; Return the alist of option values. - (args-fold* args %options - (lambda (opt name arg result) - (leave (_ "~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 - ((nixpkgs attribute) - (let-values (((expr loc) - (nixpkgs->guix-package nixpkgs attribute))) - (format #t ";; converted from ~a:~a~%~%" - (location-file loc) (location-line loc)) - (pretty-print expr (newline-rewriting-port (current-output-port))))) - (_ - (leave (_ "wrong number of arguments~%")))))) + (match args + (() + (format (current-error-port) + (_ "guix import: missing importer name~%"))) + ((or ("-h") ("--help")) + (show-help) + (exit 0)) + (("--version") + (show-version-and-exit "guix import")) + ((importer args ...) + (if (member importer importers) + (let ((expr (apply (resolve-importer importer) args))) + (pretty-print expr (newline-rewriting-port (current-output-port)))) + (format (current-error-port) + (_ "guix import: invalid importer~%")))))) -- cgit v1.2.3