From 8173ceee1f31ab562118ff5171254a4b73b71400 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 26 Jul 2016 17:49:34 +0200 Subject: import: pypi: Correctly handle new-style URLs. Fixes . * 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 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'guix') diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm index efa69081ef..343445aa22 100644 --- a/guix/import/pypi.scm +++ b/guix/import/pypi.scm @@ -33,6 +33,9 @@ (define-module (guix import pypi) #: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 @@ (define-module (guix import pypi) #: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 @@ (define (guix-package->pypi-name 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) #\-) -- cgit v1.2.3 From 201855221fa426851556b973e39f21e5ced7dfdf Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 26 Jul 2016 17:59:25 +0200 Subject: environment: Set 'GUIX_ENVIRONMENT' to the profile. * guix/scripts/environment.scm (create-environment): Set 'GUIX_ENVIRONMENT' to PROFILE. * tests/guix-environment.sh: Test it. * doc/guix.texi (Invoking guix environment): Document it. --- doc/guix.texi | 10 +++++++++- guix/scripts/environment.scm | 5 +++-- tests/guix-environment.sh | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'guix') diff --git a/doc/guix.texi b/doc/guix.texi index 8ab4522140..786fe551ba 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -5456,7 +5456,8 @@ details on Bash start-up files.}. @vindex GUIX_ENVIRONMENT @command{guix environment} defines the @code{GUIX_ENVIRONMENT} -variable in the shell it spawns. This allows users to, say, define a +variable in the shell it spawns; its value is the file name of the +profile of this environment. This allows users to, say, define a specific prompt for development environments in their @file{.bashrc} (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}): @@ -5467,6 +5468,13 @@ then fi @end example +@noindent +... or to browse the profile: + +@example +$ ls "$GUIX_ENVIRONMENT/bin" +@end example + Additionally, more than one package may be specified, in which case the union of the inputs for the given packages are used. For example, the command below spawns a shell where all of the dependencies of both Guile diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index ebe966f9cf..9f72b7bf24 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -90,8 +90,9 @@ (define (create-environment profile paths pure?) (evaluate-profile-search-paths profile paths)) ;; Give users a way to know that they're in 'guix environment', so they can - ;; adjust 'PS1' accordingly, for instance. - (setenv "GUIX_ENVIRONMENT" "t")) + ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so users can + ;; conveniently access its contents. + (setenv "GUIX_ENVIRONMENT" profile)) (define (show-search-paths profile search-paths pure?) "Display SEARCH-PATHS applied to PROFILE. When PURE? is #t, do not augment diff --git a/tests/guix-environment.sh b/tests/guix-environment.sh index 0b5123ab45..68343520b0 100644 --- a/tests/guix-environment.sh +++ b/tests/guix-environment.sh @@ -57,6 +57,10 @@ else test $? = 42 fi +# Make sure 'GUIX_ENVIRONMENT' points to the profile. +guix environment --bootstrap --ad-hoc guile-bootstrap --pure \ + -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"' + case "`uname -m`" in x86_64) # On x86_64, we should be able to create a 32-bit environment. -- cgit v1.2.3 From 9e90fc771386a288e1bcf032edbb75bbfc472e7c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 26 Jul 2016 18:18:53 +0200 Subject: profiles: Output in 'package->manifest-entry' defaults to "out". Fixes . Reported by Dylan Jeffers . * guix/profiles.scm (package->manifest-entry): Change #:output to default to "out". (packages->manifest): Add 'package?' in second 'match' clause. * tests/profiles.scm ("package->manifest-entry defaults to \"out\""): New test. --- guix/profiles.scm | 11 +++++------ tests/profiles.scm | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'guix') diff --git a/guix/profiles.scm b/guix/profiles.scm index 1adb143c16..db807a8136 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -163,9 +163,8 @@ (define (profile-manifest profile) (call-with-input-file file read-manifest) (manifest '())))) -(define* (package->manifest-entry package #:optional output) - "Return a manifest entry for the OUTPUT of package PACKAGE. When OUTPUT is -omitted or #f, use the first output of PACKAGE." +(define* (package->manifest-entry package #:optional (output "out")) + "Return a manifest entry for the OUTPUT of package PACKAGE." (let ((deps (map (match-lambda ((label package) (gexp-input package)) @@ -175,7 +174,7 @@ (define* (package->manifest-entry package #:optional output) (manifest-entry (name (package-name package)) (version (package-version package)) - (output (or output (car (package-outputs package)))) + (output output) (item package) (dependencies (delete-duplicates deps)) (search-paths (package-transitive-native-search-paths package))))) @@ -188,8 +187,8 @@ (define (packages->manifest packages) (map (match-lambda ((package output) (package->manifest-entry package output)) - (package - (package->manifest-entry package))) + ((? package? package) + (package->manifest-entry package))) packages))) (define (manifest->gexp manifest) diff --git a/tests/profiles.scm b/tests/profiles.scm index fc1dfd2bfc..028d7b6fb4 100644 --- a/tests/profiles.scm +++ b/tests/profiles.scm @@ -207,6 +207,16 @@ (define glibc #:hooks '()))) (return (derivation-inputs drv)))) +(test-assert "package->manifest-entry defaults to \"out\"" + (let ((outputs (package-outputs packages:glibc))) + (equal? (manifest-entry-output + (package->manifest-entry (package + (inherit packages:glibc) + (outputs (reverse outputs))))) + (manifest-entry-output + (package->manifest-entry packages:glibc)) + "out"))) + (test-assertm "profile-manifest, search-paths" (mlet* %store-monad ((guile -> (package -- cgit v1.2.3 From d00240c36e7bcf73f63e9e21c6ecec6f86d354ab Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 27 Jul 2016 11:44:34 +0200 Subject: zlib: Clarify when 'gzread!' can return zero. * guix/zlib.scm (gzread!): Augment docstring to clarify when zero is returned (based on reading zlib code). (make-gzip-input-port)[read!]: Remove scary comment. --- guix/zlib.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guix') diff --git a/guix/zlib.scm b/guix/zlib.scm index 51e5e9e426..40f5294ceb 100644 --- a/guix/zlib.scm +++ b/guix/zlib.scm @@ -92,7 +92,8 @@ (define gzread! (let ((proc (zlib-procedure int "gzread" (list '* '* unsigned-int)))) (lambda* (gzfile bv #:optional (start 0) (count (bytevector-length bv))) "Read up to COUNT bytes from GZFILE into BV at offset START. Return the -number of uncompressed bytes actually read." +number of uncompressed bytes actually read; it is zero if COUNT is zero or if +the end-of-stream has been reached." (let ((ret (proc (gzip-file->pointer gzfile) (bytevector->pointer bv start) count))) @@ -172,7 +173,6 @@ (define gzfile (gzdopen (fileno port) "r")) (define (read! bv start count) - ;; XXX: Can 'gzread!' return zero even though we haven't reached the EOF? (gzread! gzfile bv start count)) (unless (= buffer-size %default-buffer-size) -- cgit v1.2.3 From 688ec13c459602d475bccd3638a6802dc0a6ce23 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 27 Jul 2016 12:39:27 +0200 Subject: zlib: Protect against non-empty port internal buffers. * guix/zlib.scm (make-gzip-input-port)[gzfile]: Error out if (drain-input port) returns a non-empty string. * guix/zlib.scm (make-gzip-output-port)[gzfile]: Call 'force-output'. --- guix/zlib.scm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'guix') diff --git a/guix/zlib.scm b/guix/zlib.scm index 40f5294ceb..74420129f6 100644 --- a/guix/zlib.scm +++ b/guix/zlib.scm @@ -168,9 +168,18 @@ (define* (make-gzip-input-port port #:key (buffer-size %default-buffer-size)) "Return an input port that decompresses data read from PORT, a file port. PORT is automatically closed when the resulting port is closed. BUFFER-SIZE is the size in bytes of the internal buffer, 8 KiB by default; using a larger -buffer increases decompression speed." +buffer increases decompression speed. An error is thrown if PORT contains +buffered input, which would be lost (and is lost anyway)." (define gzfile - (gzdopen (fileno port) "r")) + (match (drain-input port) + ("" ;PORT's buffer is empty + (gzdopen (fileno port) "r")) + (_ + ;; This is unrecoverable but it's better than having the buffered input + ;; be lost, leading to unclear end-of-file or corrupt-data errors down + ;; the path. + (throw 'zlib-error 'make-gzip-input-port + "port contains buffered input" port)))) (define (read! bv start count) (gzread! gzfile bv start count)) @@ -189,8 +198,10 @@ (define* (make-gzip-output-port port a file port, as its sink. PORT is automatically closed when the resulting port is closed." (define gzfile - (gzdopen (fileno port) - (string-append "w" (number->string level)))) + (begin + (force-output port) ;empty PORT's buffer + (gzdopen (fileno port) + (string-append "w" (number->string level))))) (define (write! bv start count) (gzwrite gzfile bv start count)) -- cgit v1.2.3