;; Run with: guix time-machine -C channels.scm -- environment -m manifest.scm

;; -----------------------------
;; channels.scm
;; -----------------------------
(list (channel
       (name 'guix)
       (url "https://git.savannah.gnu.org/git/guix.git")
       (branch "master")
       (commit "v1.4.0")
       (introduction
        (make-channel-introduction
         "9edb3f66fd807b096b48283debdcddccfea34bad"
         (openpgp-fingerprint
          "BBB0 2DDF 2CEA F6A8 0D1D  E643 A2A0 6DF2 A33A 54FA"))))
      (channel
       (name 'guix-past)
       (url "https://gitlab.inria.fr/guix-hpc/guix-past")
       (commit "1e25b23faa6b1716deaf7e1782becb5da6855942")
       (introduction
        (make-channel-introduction
         "0c119db2ea86a389769f4d2b9c6f5c41c027e336"
         (openpgp-fingerprint
          "3CE4 6455 8A84 FDC6 9DB4  0CFB 090B 1199 3D9A EBB5")))))

;; -----------------------------
;; manifest.scm
;; -----------------------------

(use-modules (guix packages)
             (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))))))
     ;; This one uses the meson-build-system
     ((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)))))
     ;; This one uses the cmake-build-system
     ((member (package-name p)
              (list "pybind11")
              string=?)
      (package/inherit p
        (location (package-location p))
        (native-inputs
         (modify-inputs (package-native-inputs p)
           (replace "python" python-wrapper)))))
     (else p)))
 
  (define (cut? p)
    (and (not (member (build-system-name (package-build-system p))
                      '(python pyproject)))
         (not (member (package-name p)
                      (list "python" "python-pygobject" "pybind11")
                      string=?))))
 
  (package-mapping transform cut?))
 
(define python38-package
  (package-with-explicit-python python-3.8 "python-" "python38-"))

(packages->manifest
 (cons* python-3.8
        (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 08:40:43 2023. CET. (original)