@@ 0,0 1,121 @@
+(define-module (ruther packages python-3.12)
+ #:use-module (gnu)
+ #:use-module (guix packages)
+ #:use-module ((guix licenses) #:prefix license:)
+
+ #:use-module (guix gexp)
+ #:use-module (guix download)
+ #:use-module (guix utils)
+ #:use-module ((guix build-system copy) #:prefix copy:)
+ #:use-module ((guix build-system python) #:prefix python:)
+ #:use-module ((guix build-system pyproject) #:prefix pyproject:)
+ #:use-module (gnu packages sphinx)
+ #:use-module (gnu packages python)
+ #:use-module (gnu packages check)
+ #:use-module (gnu packages python-check)
+ #:use-module (gnu packages python-build)
+ #:use-module (gnu packages python-xyz))
+
+(define with-python-3.12-raw
+ (package-input-rewriting `((,python . ,python-3.12))))
+
+(define-public python-3.12-wrapped
+ ((@@ (gnu packages python) wrap-python3) python-3.12))
+
+(define-public python-3.12-toolchain
+ ((@@ (gnu packages python) wrap-python3)
+ (package/inherit python-3.12
+ (name "python-next-toolchain")
+ (propagated-inputs
+ (modify-inputs (package-propagated-inputs python-3.12)
+ (append (with-python-3.12-raw python-setuptools))))
+ (arguments
+ (substitute-keyword-arguments (package-arguments python-3.12)
+ ((#:tests? _ #f) #f)))))) ;; Disabled tests, because this was running forever...
+
+(define with-python-3.12-no-cython
+ (package-input-rewriting `((,python . ,python-3.12-toolchain))))
+
+;; Cython is dependency of a lot of packages, let's update it here
+(define-public python-3.12-cython
+ (with-python-3.12-no-cython
+ (package/inherit python-cython
+ (version "0.29.37")
+ (source
+ (origin
+ (method url-fetch)
+ (uri (python:pypi-uri "Cython" version))
+ (sha256
+ (base32 "1ysca2r23h12ai9wrym4ci0nvgwm3lfijrpj9xfyxbclvnkd84zq"))))
+ (arguments
+ (substitute-keyword-arguments (package-arguments python-cython)
+ ((#:tests? _ #f) #f)))))) ;; Failing... I don't know why...
+
+;; This is changed a bit compared to the original function from Guix.
+;; This one also works for pyproject
+(define* (package-with-explicit-python python old-prefix new-prefix
+ #:key variant-property)
+ "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.
+
+When VARIANT-PROPERTY is present, it is used as a key to search for
+pre-defined variants of this transformation recorded in the 'properties' field
+of packages. The property value must be the promise of a package. This is a
+convenient way for package writers to force the transformation to use
+pre-defined variants."
+ (define package-variant
+ (if variant-property
+ (lambda (package)
+ (assq-ref (package-properties package)
+ variant-property))
+ (const #f)))
+
+ (define (transform p)
+ (cond
+ ;; If VARIANT-PROPERTY is present, use that.
+ ((package-variant p)
+ => force)
+
+ ;; Otherwise build the new package object graph.
+ ((or (eq? (package-build-system p) python:python-build-system)
+ (eq? (package-build-system p) pyproject:pyproject-build-system))
+ (package/inherit p
+ (location (package-location p))
+ (name (let ((name (package-name p)))
+ (string-append new-prefix
+ (if (string-prefix? old-prefix name)
+ (substring name
+ (string-length old-prefix))
+ name))))
+ (arguments
+ (let ((python (if (promise? python)
+ (force python)
+ python)))
+ (ensure-keyword-arguments (package-arguments p)
+ `(#:python ,python))))))
+ (else p)))
+
+ (define (cut? p)
+ (or (not (and (eq? (package-build-system p) python:python-build-system)
+ (eq? (package-build-system p) pyproject:pyproject-build-system)))
+ (package-variant p)))
+
+ (package-mapping transform cut?))
+
+(define with-python-3.12-single
+ (lambda (x)
+ ((package-input-rewriting `((,python-cython . ,python-3.12-cython)
+ ;; TODO: put more stuff here, if there is something
+ ;; that's a common dependenc that will get broken on
+ ;; Python 3.12
+ ))
+ ((package-with-explicit-python python-3.12-toolchain "python-" "python-3.12-") x))))
+
+(define-public (with-python-3.12 el)
+ (if
+ (list? el)
+ (map with-python-3.12 el)
+ (with-python-3.12-single el)))