;; 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 download)
             (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)
             (ice-9 match))

(define (cut? p)
  (and (not (member (build-system-name (package-build-system p))
                    '(python pyproject)))
       ;; Do include these three packages even though they don't use
       ;; the pyproject or python build systems.
       (not (member (package-name p)
                    (list "python" "python-pygobject" "pybind11")
                    string=?))))

(define %replacements
  `(("python-coloredlogs"
     ,(pypi-uri "coloredlogs" "14.0")
     "14.0"
     "01d564fl88lkqlr888filf9iy7q35lsc823nm70acfh5sa9v3ym1")
    ("python-coverage"
     ,(pypi-uri "coverage" "5.3.1")
     "5.3.1"
     "02x5y37bkkm4cxxdfh4qax39x5bwbrgslpgdczgq5pdq2w9npw9q")
    ("python-numpy"
     "https://github.com/numpy/numpy/releases/download/v1.19.0/numpy-1.19.0.tar.gz"
     "1.19.0"
     "143bi9wrk8ggfq8zjj1vcbppybrx17zar08rjc8scmvf2yqghg0m")
    ("python-pandas"
     ,(pypi-uri "pandas" "1.0.5")
     "1.0.5"
     "1a2gv3g6jr6vb5ca43fkwjl5xf86wpfz8y3zcy787adjl0hdkib9")
    ("python-pdoc3"
     ,(pypi-uri "pdoc3" "0.9.1")
     "0.9.1"
     "15482rvpg5r70gippj3nbl58x9plgmgvp0rg4xi4dpdqhma8v171")
    ("python-scikit-learn"
     ,(pypi-uri "scikit-learn" "0.23.1")
     "0.23.1"
     "1f693g18kai2hg7rgc3z6zdf525vl6fa472qhnnr73qzhg4c3zp3")
    ("python-pytest"
     ,(pypi-uri "pytest" "5.4.3")
     "5.4.3"
     "1n67lk8iwlsmfdm8663k8l7isllg1xd3n9p1yla7885szhdk6ybr")
    ("python-pytest-cov"
     ,(pypi-uri "pytest-cov" "2.10.1")
     "2.10.1"
     "13mq1dd0hbzghvd86xyd7mccrgfpza43ywg1jfgxgzan83hhrga7")
    ("python-pytest-asyncio"
     ,(pypi-uri "pytest-asyncio" "0.14.0")
     "0.14.0"
     "00772x89c0q4kxdyhcnw8zg9pwr8nmc536lnbygl8aa4nb3c10lq")))

(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.

Also replace package sources according to %REPLACEMENTS.  It's not
elegant to do this all here at once without composing functions, but
that's okay."
  ;; 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)
    (define new-name
      (let ((name (package-name p)))
        (if (string-prefix? old-prefix name)
            (string-append new-prefix
                           (substring name (string-length old-prefix)))
            name)))
    (define-values (new-source new-version)
      (cond
       ((assoc-ref %replacements (package-name p))
        => (match-lambda*
             (((uri version hash))
              (values (origin
                        (inherit (package-source p))
                        (method url-fetch)
                        (file-name (basename uri))
                        (uri uri)
                        (sha256 (base32 hash)))
                      version))))
       (else (values (package-source p) (package-version 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 new-name)
        (version new-version)
        (source new-source)
        (arguments
         (let ((python (if (promise? python-wrapper)
                           (force python-wrapper)
                           python-wrapper))
               ;; XXX: these packages ignore the #:tests? argument.
               (args (cond
                      ((member (package-name p)
                               (list "python-pytest-asyncio")
                               string=?)
                       (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 new-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)))
  (package-mapping transform cut?))
 
(define python38-package
  (package-with-explicit-python python-3.8 "python-" "python38-"))

(packages->manifest
 (cons* python-3.8
        (map 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 20:44:31 2023. CET. (original)