guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: import: pypi: Correctly handle new-style URLs.


From: Ludovic Courtès
Subject: 01/03: import: pypi: Correctly handle new-style URLs.
Date: Tue, 26 Jul 2016 16:21:19 +0000 (UTC)

civodul pushed a commit to branch master
in repository guix.

commit 8173ceee1f31ab562118ff5171254a4b73b71400
Author: Ludovic Courtès <address@hidden>
Date:   Tue Jul 26 17:49:34 2016 +0200

    import: pypi: Correctly handle new-style URLs.
    
    Fixes <http://bugs.gnu.org/23997>.
    
    * guix/import/pypi.scm (guix-package->pypi-name): Rewrite using
    'basename' and 'hyphen-package-name->name+version'.
    * tests/pypi.scm ("guix-package->pypi-name, old URL style")
    ("guix-package->pypi-name, new URL style"): New tests.
---
 guix/import/pypi.scm |   13 +++++++------
 tests/pypi.scm       |   16 ++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm
index efa6908..343445a 100644
--- a/guix/import/pypi.scm
+++ b/guix/import/pypi.scm
@@ -33,6 +33,9 @@
   #:use-module (web uri)
   #:use-module (guix ui)
   #:use-module (guix utils)
+  #:use-module ((guix build utils)
+                #:select ((package-name->name+version
+                           . hyphen-package-name->name+version)))
   #:use-module (guix import utils)
   #:use-module ((guix download) #:prefix download:)
   #:use-module (guix import json)
@@ -41,7 +44,8 @@
   #:use-module (guix licenses)
   #:use-module (guix build-system python)
   #:use-module (gnu packages python)
-  #:export (pypi->guix-package
+  #:export (guix-package->pypi-name
+            pypi->guix-package
             %pypi-updater))
 
 (define (pypi-fetch name)
@@ -92,11 +96,8 @@ package."
   "Given a Python PACKAGE built from pypi.python.org, return the name of the
 package on PyPI."
   (let ((source-url (and=> (package-source package) origin-uri)))
-    ;; The URL has the form:
-    ;; 'https://pypi.python.org/packages/source/' +
-    ;; first letter of the package name +
-    ;; '/' + package name + '/' + ...
-    (substring source-url 42 (string-rindex source-url #\/))))
+    (hyphen-package-name->name+version
+     (basename (file-sans-extension source-url)))))
 
 (define (wheel-url->extracted-directory wheel-url)
   (match (string-split (basename wheel-url) #\-)
diff --git a/tests/pypi.scm b/tests/pypi.scm
index 379c288..01d8a57 100644
--- a/tests/pypi.scm
+++ b/tests/pypi.scm
@@ -73,6 +73,22 @@ baz > 13.37")
 
 (test-begin "pypi")
 
+(test-equal "guix-package->pypi-name, old URL style"
+  "psutil"
+  (guix-package->pypi-name
+   (dummy-package "foo"
+                  (source (dummy-origin
+                           (uri
+                            
"https://pypi.io/packages/source/p/psutil/psutil-4.3.0.tar.gz";))))))
+
+(test-equal "guix-package->pypi-name, new URL style"
+  "certbot"
+  (guix-package->pypi-name
+   (dummy-package "foo"
+                  (source (dummy-origin
+                           (uri
+                            
"https://pypi.python.org/packages/a2/3b/4756e6a0ceb14e084042a2a65c615d68d25621c6fd446d0fc10d14c4ce7d/certbot-0.8.1.tar.gz";))))))
+
 (test-assert "pypi->guix-package"
   ;; Replace network resources with sample data.
   (mock ((guix import utils) url-fetch



reply via email to

[Prev in Thread] Current Thread [Next in Thread]