summaryrefslogtreecommitdiff
path: root/guix/build/python-build-system.scm
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2021-01-03 10:30:29 +0100
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2021-02-01 11:53:43 -0500
commit09448c0994390697e876db235a3b773311795238 (patch)
tree158aef0eaa52de9de9711a9017ea3338aa8d8190 /guix/build/python-build-system.scm
parent8a15ecf0e3434f82194b8ccafbcfaafb5d323749 (diff)
downloadguix-patches-09448c0994390697e876db235a3b773311795238.tar
guix-patches-09448c0994390697e876db235a3b773311795238.tar.gz
build/python: Add a sanity check phase.
Add a new phase validating the usability of installed Python packages. * gnu/packages/aux-files/python/sanity-check.py: New file. * Makefile.am (AUX_FILES): Register it. * guix/build-system/python.scm (sanity-check.py): New variable. (lower): Add the script as an implicit input. * guix/build/python-build-system.scm: Remove trailing #t. (sanity-check): New phase. (%standard-phases): Use it. * tests/builders.scm: (make-python-dummy) (dummy-ok, dummy-dummy-nosetuptools, dummy-fail-requirements) (dummy-fail-import, dummy-fail-console-script): New variables. ("python-build-system: dummy-ok") ("python-build-system: dummy-dummy-nosetuptools") ("python-build-system: dummy-fail-requirements") ("python-build-system: dummy-fail-import") ("python-build-system: dummy-fail-console-script"): Add tests.
Diffstat (limited to 'guix/build/python-build-system.scm')
-rw-r--r--guix/build/python-build-system.scm26
1 files changed, 16 insertions, 10 deletions
diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm
index 0f2402d3a3..1fc97d1398 100644
--- a/guix/build/python-build-system.scm
+++ b/guix/build/python-build-system.scm
@@ -9,6 +9,7 @@
;;; Copyright © 2019, 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -132,6 +133,15 @@
(apply invoke "python" "./setup.py" command params)))
(error "no setup.py found")))
+(define* (sanity-check #:key tests? inputs outputs #:allow-other-keys)
+ "Ensure packages depending on this package via setuptools work properly,
+their advertised endpoints work and their top level modules are importable
+without errors."
+ (let ((sanity-check.py (assoc-ref inputs "sanity-check.py")))
+ ;; Make sure the working directory is empty (i.e. no Python modules in it)
+ (with-directory-excursion "/tmp"
+ (invoke "python" sanity-check.py (site-packages inputs outputs)))))
+
(define* (build #:key use-setuptools? #:allow-other-keys)
"Build a given Python package."
(call-setuppy "build" '() use-setuptools?)
@@ -209,8 +219,7 @@ running checks after installing the package."
;; '--invalidation-mode' option, do not generate any.
(unless <3.7?
(invoke "python" "-m" "compileall" "--invalidation-mode=unchecked-hash"
- out))
- #t))
+ out))))
(define* (wrap #:key inputs outputs #:allow-other-keys)
(define (list-of-files dir)
@@ -244,8 +253,7 @@ installed with setuptools."
(easy-install-pth (string-append site-packages "/easy-install.pth"))
(new-pth (string-append site-packages "/" name ".pth")))
(when (file-exists? easy-install-pth)
- (rename-file easy-install-pth new-pth))
- #t))
+ (rename-file easy-install-pth new-pth))))
(define* (ensure-no-mtimes-pre-1980 #:rest _)
"Ensure that there are no mtimes before 1980-01-02 in the source tree."
@@ -257,8 +265,7 @@ installed with setuptools."
(ftw "." (lambda (file stat flag)
(unless (<= early-1980 (stat:mtime stat))
(utime file early-1980 early-1980))
- #t))
- #t))
+ #t))))
(define* (enable-bytecode-determinism #:rest _)
"Improve determinism of pyc files."
@@ -266,8 +273,7 @@ installed with setuptools."
(setenv "PYTHONHASHSEED" "0")
;; Prevent Python from creating .pyc files when loading modules (such as
;; when running a test suite).
- (setenv "PYTHONDONTWRITEBYTECODE" "1")
- #t)
+ (setenv "PYTHONDONTWRITEBYTECODE" "1"))
(define* (ensure-no-cythonized-files #:rest _)
"Check the source code for @code{.c} files which may have been pre-generated
@@ -278,8 +284,7 @@ by Cython."
(string-append (string-drop-right file 3) "c")))
(when (file-exists? generated-file)
(format #t "Possible Cythonized file found: ~a~%" generated-file))))
- (find-files "." "\\.pyx$"))
- #t)
+ (find-files "." "\\.pyx$")))
(define %standard-phases
;; The build phase only builds C extensions and copies the Python sources,
@@ -301,6 +306,7 @@ by Cython."
(add-after 'install 'wrap wrap)
(add-before 'check 'add-install-to-pythonpath add-install-to-pythonpath)
(add-before 'check 'add-install-to-path add-install-to-path)
+ (add-after 'check 'sanity-check sanity-check)
(add-before 'strip 'rename-pth-file rename-pth-file)))
(define* (python-build #:key inputs (phases %standard-phases)