at 23.05-pre 2.6 kB view raw
1{ lib 2, fetchPypi 3, python 4, buildPythonPackage 5, gfortran 6, pytest 7, blas 8, lapack 9, writeTextFile 10, isPyPy 11, cython 12, setuptools 13 }: 14 15assert (!blas.isILP64) && (!lapack.isILP64); 16 17let 18 cfg = writeTextFile { 19 name = "site.cfg"; 20 text = (lib.generators.toINI {} { 21 ${blas.implementation} = { 22 include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; 23 library_dirs = "${blas}/lib:${lapack}/lib"; 24 runtime_library_dirs = "${blas}/lib:${lapack}/lib"; 25 libraries = "lapack,lapacke,blas,cblas"; 26 }; 27 lapack = { 28 include_dirs = "${lib.getDev lapack}/include"; 29 library_dirs = "${lapack}/lib"; 30 runtime_library_dirs = "${lapack}/lib"; 31 }; 32 blas = { 33 include_dirs = "${lib.getDev blas}/include"; 34 library_dirs = "${blas}/lib"; 35 runtime_library_dirs = "${blas}/lib"; 36 }; 37 }); 38 }; 39in buildPythonPackage rec { 40 pname = "numpy"; 41 version = "1.16.6"; 42 format = "pyproject"; 43 44 src = fetchPypi { 45 inherit pname version; 46 extension = "zip"; 47 sha256 = "e5cf3fdf13401885e8eea8170624ec96225e2174eb0c611c6f26dd33b489e3ff"; 48 }; 49 50 nativeBuildInputs = [ gfortran pytest cython setuptools ]; 51 buildInputs = [ blas lapack ]; 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 preConfigure = '' 61 sed -i 's/-faltivec//' numpy/distutils/system_info.py 62 export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES 63 export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES)) 64 ''; 65 66 preBuild = '' 67 ln -s ${cfg} site.cfg 68 ''; 69 70 enableParallelBuilding = true; 71 72 doCheck = !isPyPy; # numpy 1.16+ hits a bug in pypy's ctypes, using either numpy or pypy HEAD fixes this (https://github.com/numpy/numpy/issues/13807) 73 74 checkPhase = '' 75 runHook preCheck 76 pushd "$out" 77 ${python.interpreter} -c 'import numpy; numpy.test("fast", verbose=10)' 78 popd 79 runHook postCheck 80 ''; 81 82 passthru = { 83 # just for backwards compatibility 84 blas = blas.provider; 85 blasImplementation = blas.implementation; 86 inherit cfg; 87 }; 88 89 # Disable test 90 # - test_large_file_support: takes a long time and can cause the machine to run out of disk space 91 NOSE_EXCLUDE="test_large_file_support"; 92 93 meta = { 94 description = "Scientific tools for Python"; 95 homepage = "https://numpy.org/"; 96 license = lib.licenses.bsd3; 97 maintainers = with lib.maintainers; [ fridh ]; 98 }; 99}