(use-modules (guix packages) (guix build-system python)
(guix utils)
(ice-9 match))
(define packages
(list "python-numpy"
"python-pytorch"
"python-matplotlib"
"python-scipy"
"python-scikit-learn"
"python-seaborn"))
(define old-python
(specification->package "python@3.8"))
(define old-python-wrapper
((@@ (gnu packages python) wrap-python3) old-python))
(define (python-package? package)
(eq? python-build-system
(package-build-system package)))
(define (replace-python-in-inputs inputs python)
"Some packages have an explicit Python in the inputs, or use a
separate output of the Python package."
(map (match-lambda
(("python" package out) `("python" ,python ,out))
(("python" package) python)
(anything anything))
inputs))
(define (package-with-different-python pkg python-wrapper python)
"Return a new package based on PKG that uses PYTHON during the build."
(package/inherit pkg
(arguments
(ensure-keyword-arguments
(package-arguments pkg)
`(#:python ,python-wrapper
#:tests? #false))) (native-inputs
(replace-python-in-inputs (package-native-inputs pkg) python))
(inputs
(replace-python-in-inputs (package-inputs pkg) python))
(propagated-inputs
(replace-python-in-inputs (package-propagated-inputs pkg) python))))
(define use-old-python
(package-mapping
(lambda (pkg)
(if (python-package? pkg)
(let ((modified (package-with-different-python pkg
old-python-wrapper
old-python)))
(cond
((string=? (package-name pkg)
"python-importlib-metadata")
(package/inherit modified
(native-inputs
(modify-inputs (package-native-inputs modified)
(prepend (specification->package "python-setuptools"))))))
(else modified)))
pkg))
(negate python-package?)
#:deep? #false))
(define python-packages-with-old-python
(map (compose use-old-python specification->package)
packages))
(packages->manifest
(cons old-python
python-packages-with-old-python))