gnu: python-safetensors: Remove #:cargo-inputs.

* gnu/packages/machine-learning.scm (python-safetensors)
[inputs]: Use ‘cargo-inputs’.
[arguments]: Remove #:cargo-inputs.
<#:install-source?>: Disable.
<#:modules>: Unset.
<#:phases>: Simplify 'inject-safetensors and move it to...
[source]: ...here as a snippet.
* gnu/packages/rust-crates.scm (lookup-cargo-inputs)[python-safetensors]: New
entry.

Change-Id: I806770a776e02deba1e4a1dddccd608897121605
This commit is contained in:
Hilton Chain 2025-04-20 10:43:53 +08:00
parent 49d3951dae
commit f6adf70058
No known key found for this signature in database
GPG key ID: ACC66D09CA528292
2 changed files with 74 additions and 27 deletions

View file

@ -1430,31 +1430,15 @@ storing tensors safely, named safetensors. They aim to be safer than their
(unless (member file '("." ".."))
(rename-file (string-append "bindings/python/" file)
file)))
(scandir "bindings/python"))))))
(scandir "bindings/python"))
(substitute* "Cargo.toml"
(("^path = .*") ""))))))
(build-system cargo-build-system)
(arguments
(list
#:modules '((guix build cargo-build-system)
(guix build utils)
(ice-9 regex)
(ice-9 textual-ports)
(srfi srfi-26))
#:install-source? #f
#:phases
#~(modify-phases %standard-phases
(add-after 'unpack-rust-crates 'inject-safetensors
(lambda _
(substitute* "Cargo.toml"
(("\\[dependencies\\]")
(format #f "[dependencies]~%safetensors = ~s"
#$(package-version rust-safetensors))))
(call-with-input-file "Cargo.toml"
(lambda (port)
(let* ((content (get-string-all port))
(top-match (string-match
"\\[dependencies.safetensors"
content)))
(call-with-output-file "Cargo.toml"
(cut display (match:prefix top-match) <>)))))))
(add-before 'check 'install-rust-library
(lambda _
(copy-file "target/release/libsafetensors_rust.so"
@ -1484,14 +1468,9 @@ storing tensors safely, named safetensors. They aim to be safer than their
(copy-file "PKG-INFO" (string-append info "/METADATA"))
(copy-recursively
"py_src/safetensors"
(string-append lib "safetensors"))))))
#:cargo-inputs
`(("rust-pyo3" ,rust-pyo3-0.21)
("rust-memmap2" ,rust-memmap2-0.9)
("rust-safetensors" ,rust-safetensors)
("rust-serde-json" ,rust-serde-json-1))))
(string-append lib "safetensors"))))))))
(inputs
(list rust-safetensors))
(cargo-inputs 'python-safetensors))
(native-inputs
(list python-h5py
python-minimal