Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 fetchPypi, 5 python, 6 numpy_1, 7 pythonAtLeast, 8 pythonOlder, 9 buildPythonPackage, 10 writeTextFile, 11 12 # build-system 13 cython, 14 gfortran, 15 meson-python, 16 mesonEmulatorHook, 17 pkg-config, 18 xcbuild, 19 20 # native dependencies 21 blas, 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 37let 38 cfg = writeTextFile { 39 name = "site.cfg"; 40 text = lib.generators.toINI { } { 41 ${blas.implementation} = { 42 include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; 43 library_dirs = "${blas}/lib:${lapack}/lib"; 44 runtime_library_dirs = "${blas}/lib:${lapack}/lib"; 45 libraries = "lapack,lapacke,blas,cblas"; 46 }; 47 lapack = { 48 include_dirs = "${lib.getDev lapack}/include"; 49 library_dirs = "${lapack}/lib"; 50 runtime_library_dirs = "${lapack}/lib"; 51 }; 52 blas = { 53 include_dirs = "${lib.getDev blas}/include"; 54 library_dirs = "${blas}/lib"; 55 runtime_library_dirs = "${blas}/lib"; 56 }; 57 }; 58 }; 59in 60buildPythonPackage rec { 61 pname = "numpy"; 62 version = "1.26.4"; 63 pyproject = true; 64 disabled = pythonOlder "3.9" || pythonAtLeast "3.13"; 65 66 src = fetchPypi { 67 inherit pname version; 68 extension = "tar.gz"; 69 hash = "sha256-KgKrqe0S5KxOs+qUIcQgMBoMZGDZgw10qd+H76SRIBA="; 70 }; 71 72 patches = [ 73 # Disable `numpy/core/tests/test_umath.py::TestComplexFunctions::test_loss_of_precision[complex256]` 74 # on x86_64-darwin because it fails under Rosetta 2 due to issues with trig functions and 75 # 80-bit long double complex numbers. 76 ./disable-failing-long-double-test-Rosetta-2.patch 77 ] 78 # We patch cpython/distutils to fix https://bugs.python.org/issue1222585 79 # Patching of numpy.distutils is needed to prevent it from undoing the 80 # patch to distutils. 81 ++ lib.optionals python.hasDistutilsCxxPatch [ ./numpy-distutils-C++.patch ]; 82 83 postPatch = '' 84 # fails with multiple errors because we are not using the pinned setuptools version 85 # see https://github.com/numpy/numpy/blob/v1.25.0/pyproject.toml#L7 86 # error: option --single-version-externally-managed not recognized 87 # TypeError: dist must be a Distribution instance 88 rm numpy/core/tests/test_cython.py 89 90 patchShebangs numpy/_build_utils/*.py 91 92 # remove needless reference to full Python path stored in built wheel 93 substituteInPlace numpy/meson.build \ 94 --replace 'py.full_path()' "'python'" 95 96 substituteInPlace pyproject.toml \ 97 --replace-fail "meson-python>=0.15.0,<0.16.0" "meson-python" 98 ''; 99 100 nativeBuildInputs = [ 101 cython 102 gfortran 103 meson-python 104 pkg-config 105 ] 106 ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ xcbuild.xcrun ] 107 ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ mesonEmulatorHook ]; 108 109 buildInputs = [ 110 blas 111 lapack 112 ]; 113 114 # Causes `error: argument unused during compilation: '-fno-strict-overflow'` due to `-Werror`. 115 hardeningDisable = lib.optionals stdenv.cc.isClang [ "strictoverflow" ]; 116 117 # we default openblas to build with 64 threads 118 # if a machine has more than 64 threads, it will segfault 119 # see https://github.com/OpenMathLib/OpenBLAS/issues/2993 120 preConfigure = '' 121 sed -i 's/-faltivec//' numpy/distutils/system_info.py 122 export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES)) 123 ''; 124 125 preBuild = '' 126 ln -s ${cfg} site.cfg 127 ''; 128 129 enableParallelBuilding = true; 130 131 nativeCheckInputs = [ 132 pytest-xdist 133 pytestCheckHook 134 hypothesis 135 setuptools 136 typing-extensions 137 ]; 138 139 preCheck = '' 140 cd "$out" 141 ''; 142 143 # https://github.com/numpy/numpy/blob/a277f6210739c11028f281b8495faf7da298dbef/numpy/_pytesttester.py#L180 144 disabledTestMarks = [ 145 "slow" # fast test suite 146 ]; 147 148 # https://github.com/numpy/numpy/issues/24548 149 disabledTests = [ 150 # Tries to import numpy.distutils.msvccompiler, removed in setuptools 74.0 151 "test_api_importable" 152 ] 153 ++ lib.optionals stdenv.hostPlatform.isi686 [ 154 "test_new_policy" # AssertionError: assert False 155 "test_identityless_reduction_huge_array" # ValueError: Maximum allowed dimension exceeded 156 "test_float_remainder_overflow" # AssertionError: FloatingPointError not raised by divmod 157 "test_int" # AssertionError: selectedintkind(19): expected 16 but got -1 158 ] 159 ++ lib.optionals stdenv.hostPlatform.isAarch32 [ 160 "test_impossible_feature_enable" # AssertionError: Failed to generate error 161 "test_features" # AssertionError: Failure Detection 162 "test_new_policy" # AssertionError: assert False 163 "test_identityless_reduction_huge_array" # ValueError: Maximum allowed dimension exceeded 164 "test_unary_spurious_fpexception" # AssertionError: Got warnings: [<warnings.WarningMessage object at 0xd1197430>] 165 "test_int" # AssertionError: selectedintkind(19): expected 16 but got -1 166 "test_real" # AssertionError: selectedrealkind(16): expected 10 but got -1 167 "test_quad_precision" # AssertionError: selectedrealkind(32): expected 16 but got -1 168 "test_big_arrays" # ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger tha... 169 "test_multinomial_pvals_float32" # Failed: DID NOT RAISE <class 'ValueError'> 170 ] 171 ++ lib.optionals stdenv.hostPlatform.isAarch64 [ 172 "test_big_arrays" # OOM on a 16G machine 173 ] 174 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [ 175 # can fail on virtualized machines confused over their cpu identity 176 "test_dispatcher" 177 ]; 178 179 passthru = { 180 # just for backwards compatibility 181 blas = blas.provider; 182 blasImplementation = blas.implementation; 183 inherit cfg; 184 coreIncludeDir = "${numpy_1}/${python.sitePackages}/numpy/core/include"; 185 tests = { 186 inherit sage; 187 }; 188 }; 189 190 # Disable test 191 # - test_large_file_support: takes a long time and can cause the machine to run out of disk space 192 env.NOSE_EXCLUDE = "test_large_file_support"; 193 194 meta = { 195 changelog = "https://github.com/numpy/numpy/releases/tag/v${version}"; 196 description = "Scientific tools for Python"; 197 mainProgram = "f2py"; 198 homepage = "https://numpy.org/"; 199 license = lib.licenses.bsd3; 200 }; 201}