(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) (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)))
(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."
(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
((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))
(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))))
(propagated-inputs
(cond
((string=? (package-name p) "python-matplotlib")
(modify-inputs (package-propagated-inputs p)
(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 new-name)
(native-inputs
(modify-inputs (package-native-inputs p)
(replace "python-wrapper" python-wrapper)))
(inputs
(modify-inputs (package-inputs p)
(replace "python" python)))))
((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))))