nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 22.05 113 lines 2.9 kB view raw
1{ lib 2, fetchPypi 3, fetchpatch 4, python 5, buildPythonPackage 6, gfortran 7, hypothesis 8, pytest 9, blas 10, lapack 11, writeTextFile 12, cython 13, setuptoolsBuildHook 14, pythonOlder 15}: 16 17assert (!blas.isILP64) && (!lapack.isILP64); 18 19let 20 cfg = writeTextFile { 21 name = "site.cfg"; 22 text = (lib.generators.toINI {} { 23 ${blas.implementation} = { 24 include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; 25 library_dirs = "${blas}/lib:${lapack}/lib"; 26 runtime_library_dirs = "${blas}/lib:${lapack}/lib"; 27 libraries = "lapack,lapacke,blas,cblas"; 28 }; 29 lapack = { 30 include_dirs = "${lib.getDev lapack}/include"; 31 library_dirs = "${lapack}/lib"; 32 runtime_library_dirs = "${lapack}/lib"; 33 }; 34 blas = { 35 include_dirs = "${lib.getDev blas}/include"; 36 library_dirs = "${blas}/lib"; 37 runtime_library_dirs = "${blas}/lib"; 38 }; 39 }); 40 }; 41in buildPythonPackage rec { 42 pname = "numpy"; 43 44 # Attention! v1.22.0 breaks scipy and by extension scikit-learn, so 45 # build both to verify they don't break. 46 # https://github.com/scipy/scipy/issues/15414 47 version = "1.21.5"; 48 49 format = "pyproject.toml"; 50 disabled = pythonOlder "3.7"; 51 52 src = fetchPypi { 53 inherit pname version; 54 extension = "zip"; 55 sha256 = "sha256-alkovGJBJk3OXtUJ5m8zZ2/Jf0ZOepGe3GcvtVMiIe4="; 56 }; 57 58 patches = lib.optionals python.hasDistutilsCxxPatch [ 59 # We patch cpython/distutils to fix https://bugs.python.org/issue1222585 60 # Patching of numpy.distutils is needed to prevent it from undoing the 61 # patch to distutils. 62 ./numpy-distutils-C++.patch 63 ]; 64 65 nativeBuildInputs = [ gfortran cython setuptoolsBuildHook ]; 66 buildInputs = [ blas lapack ]; 67 68 # we default openblas to build with 64 threads 69 # if a machine has more than 64 threads, it will segfault 70 # see https://github.com/xianyi/OpenBLAS/issues/2993 71 preConfigure = '' 72 sed -i 's/-faltivec//' numpy/distutils/system_info.py 73 export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES 74 export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES)) 75 ''; 76 77 preBuild = '' 78 ln -s ${cfg} site.cfg 79 ''; 80 81 enableParallelBuilding = true; 82 83 checkInputs = [ 84 pytest 85 hypothesis 86 ]; 87 88 checkPhase = '' 89 runHook preCheck 90 pushd dist 91 ${python.interpreter} -c 'import numpy; numpy.test("fast", verbose=10)' 92 popd 93 runHook postCheck 94 ''; 95 96 passthru = { 97 # just for backwards compatibility 98 blas = blas.provider; 99 blasImplementation = blas.implementation; 100 inherit cfg; 101 }; 102 103 # Disable test 104 # - test_large_file_support: takes a long time and can cause the machine to run out of disk space 105 NOSE_EXCLUDE="test_large_file_support"; 106 107 meta = { 108 description = "Scientific tools for Python"; 109 homepage = "https://numpy.org/"; 110 license = lib.licenses.bsd3; 111 maintainers = with lib.maintainers; [ fridh ]; 112 }; 113}