(use-modules (guix packages)
             (guix download)
             (guix build-system)
             (guix utils)
             (guix transformations)
             (gnu packages check)
             (gnu packages machine-learning)
             (gnu packages python)
             (gnu packages python-science)
             (gnu packages python-xyz)
             (past packages python) ;for python-3.8
             (guix build-system python)
             (guix build-system pyproject)
             (srfi srfi-1))

(define transform
  (options->transformation
   `((with-source . ,(string-append "python38-coloredlogs=" (pypi-uri "coloredlogs" "14.0")))
     (with-source . ,(string-append "python38-coverage=" (pypi-uri "coverage" "5.3.1")))
     (with-source . "python38-numpy=https://github.com/numpy/numpy/releases/download/v1.19.0/numpy-1.19.0.tar.gz")
     (with-source . ,(string-append "python38-pandas=" (pypi-uri "pandas" "1.0.5")))
     (with-source . ,(string-append "python38-pdoc3=" (pypi-uri "pdoc3" "0.9.1")))
     (with-source . ,(string-append "python38-scikit-learn=" (pypi-uri "scikit-learn" "0.23.1")))
     (with-source . ,(string-append "python38-pytest=" (pypi-uri "pytest" "5.4.3")))
     (with-source . ,(string-append "python38-pytest-cov=" (pypi-uri "pytest-cov" "2.10.1")))
     (with-source . ,(string-append "python38-pytest-asyncio=" (pypi-uri "pytest-asyncio" "0.14.0"))))))

;; This provides the "python" executable needed by the build
;; procedures of most Python packages.
(define python-3.8-wrapper
  ((@@ (gnu packages python) wrap-python3) python-3.8))

(define* (package-with-explicit-python python old-prefix new-prefix)
  "Return a procedure of one argument, P.  The procedure creates a package with
the same fields as P, which is assumed to use PYTHON-BUILD-SYSTEM, such that
it is compiled with PYTHON instead.  The inputs are changed recursively
accordingly.  If the name of P starts with OLD-PREFIX, this is replaced by
NEW-PREFIX; otherwise, NEW-PREFIX is prepended to the name."
  (define (transform p)
    (cond
     ;; Build the new package object graph.
     ((or (eq? (package-build-system p) python-build-system)
          (eq? (package-build-system p) pyproject-build-system))
      (package/inherit p
        (location (package-location p))
        (name (let ((name (package-name p)))
                (if (string-prefix? old-prefix name)
                    (string-append new-prefix
                                   (substring name (string-length old-prefix)))
                    name)))
        (arguments
         (let ((python (if (promise? python)
                           (force python)
                           python))
               ;; XXX: python38-pytest-asyncio ignores the #:tests? argument.
               (args (if (string=? (package-name p) "python-pytest-asyncio")
                         (substitute-keyword-arguments (package-arguments p)
                           ((#:phases phases)
                            #~(alist-delete 'check #$phases)))
                         (package-arguments p))))
           (ensure-keyword-arguments args
                                     `(#:python ,python
                                       #:tests? #false))))))
     (else p)))
 
  (define (cut? p)
    (let ((stop?
           (or (not (member (build-system-name (package-build-system p))
                            '(python pyproject)))
               #;
               (member (package-name p)
                       (list "python" "inkscape")
                       string=?))))
      (unless stop?
        (pk 'will-build (package-name p) (package-build-system p)))
      stop?))
 
  (package-mapping transform cut?))
 
(define python38-package
  (package-with-explicit-python python-3.8-wrapper "python-" "python38-"))

(packages->manifest
 (map (compose transform python38-package)
      (list
       python-coloredlogs
       python-coverage
       python-numpy
       python-pandas
       python-pdoc3
       python-scikit-learn
       python-pytest
       python-pytest-cov)))

Generated by Ricardo Wurmus using scpaste at Sat Oct 28 22:30:33 2023. CEST. (original)