;;; Manifest to build the latest Python packages with Python 3.8. (use-modules (guix packages) ; for "package", "package-arguments"... (guix build-system python) (guix transformations)) ;; The list of Python packages (or rather specifications) that we want ;; to build with an older Python. (define packages (list "python-numpy" "python-pytorch" "python-matplotlib" "python-scipy" "python-scikit-learn" "python-seaborn")) (define old-python ;; We use wrap-python3 to create a "python" executable. Python ;; itself only comes with "python3". Python 3.8 is available in the ;; guix-past channel. ((@@ (gnu packages python) wrap-python3) (specification->package "python@3.8"))) ;; We use this to replace "python" with "python@3.8", no matter if the ;; package is using the python-build-system or not. The ;; "package-mapping" thing below treats packages using the ;; python-build-system specially to make sure that the build system ;; argument "#:python" is set. (define transform-inputs (options->transformation '((with-input . "python=python@3.8")))) (define (python-package? package) (eq? python-build-system (package-build-system package))) ;; This is a recursive package transformer. When given a package ;; "pkg" it checks if it is a Python package by looking at its build ;; system; if that is the case, it will return a package variant that ;; is built with the old Python. It does this recursively, so all ;; dependencies are also modified. (define use-old-python (package-mapping (lambda (pkg) (if (python-package? pkg) ;; It’s a Python package! Return a new package that inherits ;; from the original, but build it with the old Python by ;; adding a build system argument. (package (inherit pkg) (arguments (append `(#:python ,old-python) (package-arguments pkg)))) ;; Not a Python package. Don’t change it. pkg)))) ;; Apply the transformer to the list of packages. (define python-packages-with-old-python (map (compose use-old-python specification->package) packages)) ;; Build a manifest from the list of modified packages and the old ;; Python variant itself. (packages->manifest (cons old-python python-packages-with-old-python))