(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-build)
             (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"))))))

(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."
  ;; This provides the "python" executable needed by the build
  ;; procedures of most Python packages.
  (define python-wrapper
    ((@@ (gnu packages python) wrap-python3) python))
  (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-wrapper)
                           (force python-wrapper)
                           python-wrapper))
               ;; XXX: python38-pytest-asyncio ignores the #:tests? argument.
               (args (cond
                      ((string=? (package-name p) "python-pytest-asyncio")
                       (substitute-keyword-arguments (package-arguments p)
                         ((#:phases phases)
                          #~(alist-delete 'check #$phases))))
                      (else
                       (package-arguments p)))))
           (ensure-keyword-arguments args
                                     `(#:python ,python
                                       #:tests? #false))))
        ;; Bleh, matplotlib uses python:tk and for some reason this is
        ;; not rewritten.
        (propagated-inputs
         (cond
          ((string=? (package-name p) "python-matplotlib")
           (modify-inputs (package-propagated-inputs p)
             ;;XXX: this is a bug.  The tk output is just labelled as "python".
             (replace "python" `(,python "tk"))))
          (else
           (package-propagated-inputs p))))
        (native-inputs
         (cond
          ((string=? (package-name p) "python-importlib-metadata")
           (modify-inputs (package-native-inputs p)
             (append python-setuptools)))
          (else
           (package-native-inputs p))))))
     ((member (package-name p)
              (list "python-pygobject")
              string=?)
      (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)))
        (native-inputs
         (modify-inputs (package-native-inputs p)
           (replace "python-wrapper" python-wrapper)))
        (inputs
         (modify-inputs (package-inputs p)
           (replace "python" python)))))
     (else p)))
 
  (define (cut? p)
    (let ((stop?
           (and (not (member (build-system-name (package-build-system p))
                             '(python pyproject)))
                (not (member (package-name p)
                             (list "python" "python-pygobject")
                             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 "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 Mon Oct 30 00:26:25 2023. CET. (original)