From 09448c0994390697e876db235a3b773311795238 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 3 Jan 2021 10:30:29 +0100 Subject: 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. --- guix/build/python-build-system.scm | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'guix/build/python-build-system.scm') 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 ;;; Copyright © 2020 Jakub Kądziołka ;;; Copyright © 2020 Efraim Flashner +;;; Copyright © 2021 Lars-Dominik Braun ;;; ;;; This file is part of GNU Guix. ;;; @@ -132,6 +133,15 @@ (define (call-setuppy command params use-setuptools?) (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 @@ (define* (install #:key inputs outputs (configure-flags '()) use-setuptools? ;; '--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 @@ (define* (rename-pth-file #:key name inputs outputs #:allow-other-keys) (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 @@ (define* (ensure-no-mtimes-pre-1980 #:rest _) (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 @@ (define* (enable-bytecode-determinism #:rest _) (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 @@ (define* (ensure-no-cythonized-files #:rest _) (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 @@ (define %standard-phases (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) -- cgit v1.2.3