nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 193 lines 5.8 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 python, 6 pythonAtLeast, 7 pythonOlder, 8 buildPythonPackage, 9 writeTextFile, 10 11 # build-system 12 cython, 13 gfortran, 14 meson-python, 15 mesonEmulatorHook, 16 pkg-config, 17 xcbuild, 18 19 # native dependencies 20 blas, 21 coreutils, 22 lapack, 23 24 # Reverse dependency 25 sage, 26 27 # tests 28 hypothesis, 29 pytest-xdist, 30 pytestCheckHook, 31 setuptools, 32 typing-extensions, 33}: 34 35assert (!blas.isILP64) && (!lapack.isILP64); 36 37buildPythonPackage (finalAttrs: { 38 pname = "numpy"; 39 version = "2.4.1"; 40 pyproject = true; 41 42 disabled = pythonOlder "3.11"; 43 44 src = fetchFromGitHub { 45 owner = "numpy"; 46 repo = "numpy"; 47 tag = "v${finalAttrs.version}"; 48 fetchSubmodules = true; 49 hash = "sha256-3UjvAQZEvsA/1s2mqFMnvi2E9MBHG27xf91FqiMGHmo="; 50 }; 51 52 patches = lib.optionals python.hasDistutilsCxxPatch [ 53 # We patch cpython/distutils to fix https://bugs.python.org/issue1222585 54 # Patching of numpy.distutils is needed to prevent it from undoing the 55 # patch to distutils. 56 ./numpy-distutils-C++.patch 57 ]; 58 59 postPatch = '' 60 # remove needless reference to full Python path stored in built wheel 61 substituteInPlace numpy/meson.build \ 62 --replace-fail 'py.full_path()' "'python'" 63 64 # Test_POWER_Features::test_features - FileNotFoundError: [Errno 2] No such file or directory: '/bin/true' 65 substituteInPlace numpy/_core/tests/test_cpu_features.py \ 66 --replace-fail '/bin/true' '${lib.getExe' coreutils "true"}' 67 ''; 68 69 build-system = [ 70 cython 71 gfortran 72 meson-python 73 pkg-config 74 ] 75 ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild.xcrun ] 76 ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ mesonEmulatorHook ]; 77 78 # we default openblas to build with 64 threads 79 # if a machine has more than 64 threads, it will segfault 80 # see https://github.com/OpenMathLib/OpenBLAS/issues/2993 81 preConfigure = '' 82 sed -i 's/-faltivec//' numpy/distutils/system_info.py 83 export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES)) 84 ''; 85 86 buildInputs = [ 87 blas 88 lapack 89 ]; 90 91 preBuild = '' 92 ln -s ${finalAttrs.finalPackage.passthru.cfg} site.cfg 93 ''; 94 95 enableParallelBuilding = true; 96 97 nativeCheckInputs = [ 98 hypothesis 99 pytestCheckHook 100 pytest-xdist 101 setuptools 102 typing-extensions 103 ]; 104 105 preCheck = '' 106 pushd $out 107 # For numpy-config executable to be available during tests 108 export PATH=$PATH:$out/bin 109 ''; 110 111 postCheck = '' 112 popd 113 ''; 114 115 # https://github.com/numpy/numpy/blob/a277f6210739c11028f281b8495faf7da298dbef/numpy/_pytesttester.py#L180 116 disabledTestMarks = [ 117 "slow" # fast test suite 118 ]; 119 120 disabledTests = [ 121 # Tries to import numpy.distutils.msvccompiler, removed in setuptools 74.0 122 "test_api_importable" 123 ] 124 ++ lib.optionals (pythonAtLeast "3.13") [ 125 # https://github.com/numpy/numpy/issues/26713 126 "test_iter_refcount" 127 ] 128 ++ lib.optionals stdenv.hostPlatform.isAarch32 [ 129 # https://github.com/numpy/numpy/issues/24548 130 "test_impossible_feature_enable" # AssertionError: Failed to generate error 131 "test_features" # AssertionError: Failure Detection 132 "test_new_policy" # AssertionError: assert False 133 "test_identityless_reduction_huge_array" # ValueError: Maximum allowed dimension exceeded 134 "test_unary_spurious_fpexception" # AssertionError: Got warnings: [<warnings.WarningMessage object at 0xd1197430>] 135 "test_int" # AssertionError: selectedintkind(19): expected 16 but got -1 136 "test_real" # AssertionError: selectedrealkind(16): expected 10 but got -1 137 "test_quad_precision" # AssertionError: selectedrealkind(32): expected 16 but got -1 138 "test_big_arrays" # ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger tha... 139 "test_multinomial_pvals_float32" # Failed: DID NOT RAISE <class 'ValueError'> 140 ] 141 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [ 142 # AssertionError: (np.int64(0), np.longdouble('9.9999999999999994515e-21'), np.longdouble('3.9696755572509052902e+20'), 'arctanh') 143 "test_loss_of_precision" 144 ] 145 ++ lib.optionals (stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian) [ 146 # https://github.com/numpy/numpy/issues/29918 147 "test_sq_cases" 148 ] 149 ++ lib.optionals (stdenv.hostPlatform ? gcc.arch) [ 150 # remove if https://github.com/numpy/numpy/issues/27460 is resolved 151 "test_validate_transcendentals" 152 ]; 153 154 passthru = { 155 # just for backwards compatibility 156 blas = blas.provider; 157 blasImplementation = blas.implementation; 158 buildConfig = { 159 ${blas.implementation} = { 160 include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; 161 library_dirs = "${blas}/lib:${lapack}/lib"; 162 runtime_library_dirs = "${blas}/lib:${lapack}/lib"; 163 libraries = "lapack,lapacke,blas,cblas"; 164 }; 165 lapack = { 166 include_dirs = "${lib.getDev lapack}/include"; 167 library_dirs = "${lapack}/lib"; 168 runtime_library_dirs = "${lapack}/lib"; 169 }; 170 blas = { 171 include_dirs = "${lib.getDev blas}/include"; 172 library_dirs = "${blas}/lib"; 173 runtime_library_dirs = "${blas}/lib"; 174 }; 175 }; 176 cfg = writeTextFile { 177 name = "site.cfg"; 178 text = lib.generators.toINI { } finalAttrs.finalPackage.buildConfig; 179 }; 180 coreIncludeDir = "${finalAttrs.finalPackage}/${python.sitePackages}/numpy/_core/include"; 181 tests = { 182 inherit sage; 183 }; 184 }; 185 186 meta = { 187 changelog = "https://github.com/numpy/numpy/releases/tag/${finalAttrs.src.tag}"; 188 description = "Scientific tools for Python"; 189 homepage = "https://numpy.org/"; 190 license = lib.licenses.bsd3; 191 maintainers = with lib.maintainers; [ doronbehar ]; 192 }; 193})