nixpkgs/pkgs/development/python-modules/safetensors/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

82 lines
1.8 KiB
Nix

{
lib,
stdenv,
buildPythonPackage,
fetchFromGitHub,
rustPlatform,
# nativeBuildInputs
cargo,
rustc,
setuptools-rust,
# buildInputs
libiconv,
# tests
h5py,
numpy,
pytestCheckHook,
torch,
}:
buildPythonPackage rec {
pname = "safetensors";
version = "0.4.5";
pyproject = true;
src = fetchFromGitHub {
owner = "huggingface";
repo = "safetensors";
rev = "refs/tags/v${version}";
hash = "sha256-gr4hBbecaGHaoNhRQQXWfLfNB0/wQPKftSiTnGgngog=";
};
cargoDeps = rustPlatform.fetchCargoTarball {
inherit src;
sourceRoot = "${src.name}/bindings/python";
hash = "sha256-zDXzEVvmJF1dEVUFGBc3losr9U1q/qJCjNFkdJ/pCd4=";
};
sourceRoot = "${src.name}/bindings/python";
nativeBuildInputs = [
cargo
rustc
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
setuptools-rust
];
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
nativeCheckInputs = [
h5py
numpy
pytestCheckHook
torch
];
pytestFlagsArray = [ "tests" ];
# don't require PaddlePaddle (not in Nixpkgs), Flax, or Tensorflow (onerous) to run tests:
disabledTestPaths =
[
"tests/test_flax_comparison.py"
"tests/test_paddle_comparison.py"
"tests/test_tf_comparison.py"
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# don't require mlx (not in Nixpkgs) to run tests
"tests/test_mlx_comparison.py"
];
pythonImportsCheck = [ "safetensors" ];
meta = {
homepage = "https://github.com/huggingface/safetensors";
description = "Fast (zero-copy) and safe (unlike pickle) format for storing tensors";
changelog = "https://github.com/huggingface/safetensors/releases/tag/v${version}";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ bcdarwin ];
};
}