Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 23.05 110 lines 2.9 kB view raw
1{ lib 2, fetchPypi 3, fetchpatch 4, python 5, buildPythonPackage 6, gfortran 7, hypothesis 8, pytest 9, typing-extensions 10, blas 11, lapack 12, writeTextFile 13, cython 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 version = "1.24.2"; 44 format = "setuptools"; 45 disabled = pythonOlder "3.7"; 46 47 src = fetchPypi { 48 inherit pname version; 49 extension = "tar.gz"; 50 hash = "sha256-ADqfUw6IDLLNF3y6GvciC5qkLe+cSvwqL8Pua+frKyI="; 51 }; 52 53 patches = lib.optionals python.hasDistutilsCxxPatch [ 54 # We patch cpython/distutils to fix https://bugs.python.org/issue1222585 55 # Patching of numpy.distutils is needed to prevent it from undoing the 56 # patch to distutils. 57 ./numpy-distutils-C++.patch 58 ]; 59 60 nativeBuildInputs = [ gfortran cython ]; 61 buildInputs = [ blas lapack ]; 62 63 # we default openblas to build with 64 threads 64 # if a machine has more than 64 threads, it will segfault 65 # see https://github.com/xianyi/OpenBLAS/issues/2993 66 preConfigure = '' 67 sed -i 's/-faltivec//' numpy/distutils/system_info.py 68 export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES 69 export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES)) 70 ''; 71 72 preBuild = '' 73 ln -s ${cfg} site.cfg 74 ''; 75 76 enableParallelBuilding = true; 77 78 nativeCheckInputs = [ 79 pytest 80 # "hypothesis" indirectly depends on numpy to build its documentation. 81 (hypothesis.override { enableDocumentation = false; }) 82 typing-extensions 83 ]; 84 85 checkPhase = '' 86 runHook preCheck 87 pushd "$out" 88 ${python.interpreter} -c 'import numpy; numpy.test("fast", verbose=10)' 89 popd 90 runHook postCheck 91 ''; 92 93 passthru = { 94 # just for backwards compatibility 95 blas = blas.provider; 96 blasImplementation = blas.implementation; 97 inherit cfg; 98 }; 99 100 # Disable test 101 # - test_large_file_support: takes a long time and can cause the machine to run out of disk space 102 NOSE_EXCLUDE="test_large_file_support"; 103 104 meta = { 105 description = "Scientific tools for Python"; 106 homepage = "https://numpy.org/"; 107 license = lib.licenses.bsd3; 108 maintainers = with lib.maintainers; [ fridh ]; 109 }; 110}