diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-09-27 10:16:23 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-09-29 19:30:28 -0400 |
commit | 1b3e968512ebbccf02d00c52f7e089156946f445 (patch) | |
tree | c45d203439ab9a74d01f2c76850cafb847a755e2 /guix/import/utils.scm | |
parent | 2efb3ddaa434b86a841dffbba89e21d2d9208526 (diff) |
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.
Diffstat (limited to 'guix/import/utils.scm')
-rw-r--r-- | guix/import/utils.scm | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/guix/import/utils.scm b/guix/import/utils.scm new file mode 100644 index 0000000000..062cfc54f3 --- /dev/null +++ b/guix/import/utils.scm @@ -0,0 +1,51 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> +;;; +;;; 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 utils) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) + #:use-module (srfi srfi-1) + #:export (factorize-uri)) + +(define (factorize-uri uri version) + "Factorize URI, a package tarball URI as a string, such that any occurrences +of the string VERSION is replaced by the symbol 'version." + (let ((version-rx (make-regexp (regexp-quote version)))) + (match (regexp-exec version-rx uri) + (#f + uri) + (_ + (let ((indices (fold-matches version-rx uri + '((0)) + (lambda (m result) + (match result + (((start) rest ...) + `((,(match:end m)) + (,start . ,(match:start m)) + ,@rest))))))) + (fold (lambda (index result) + (match index + ((start) + (cons (substring uri start) + result)) + ((start . end) + (cons* (substring uri start end) + 'version + result)))) + '() + indices)))))) |