at 25.11-pre 7.1 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 writeText, 6 python, 7 buildPythonPackage, 8 fetchFromGitHub, 9 fetchpatch, 10 11 # build-system 12 cython, 13 gfortran, 14 meson-python, 15 nukeReferences, 16 pythran, 17 pkg-config, 18 setuptools, 19 xcbuild, 20 21 # buildInputs 22 # Upstream has support for using Darwin's Accelerate package. However this 23 # requires a Darwin user to work on a nice way to do that via an override. 24 # See: 25 # https://github.com/scipy/scipy/blob/v1.14.0/scipy/meson.build#L194-L211 26 blas, 27 lapack, 28 pybind11, 29 pooch, 30 xsimd, 31 32 # dependencies 33 numpy, 34 35 # tests 36 hypothesis, 37 pytestCheckHook, 38 pytest-xdist, 39 40 # Reverse dependency 41 sage, 42}: 43 44let 45 pname = "scipy"; 46 # DON'T UPDATE THESE ATTRIBUTES MANUALLY - USE: 47 # 48 # nix-shell maintainers/scripts/update.nix --argstr package python3.pkgs.scipy 49 # 50 # The update script uses sed regexes to replace them with the updated hashes. 51 version = "1.15.3"; 52 srcHash = "sha256-97z5CLRq/2kWjL2+ewHRA71vSfvCLHVJdOUZfDFnyhM="; 53 datasetsHashes = { 54 ascent = "1qjp35ncrniq9rhzb14icwwykqg2208hcssznn3hz27w39615kh3"; 55 ecg = "1bwbjp43b7znnwha5hv6wiz3g0bhwrpqpi75s12zidxrbwvd62pj"; 56 face = "11i8x29h80y7hhyqhil1fg8mxag5f827g33lhnsf44qk116hp2wx"; 57 }; 58 datasets = lib.mapAttrs ( 59 d: hash: 60 fetchurl { 61 url = "https://raw.githubusercontent.com/scipy/dataset-${d}/main/${d}.dat"; 62 sha256 = hash; 63 } 64 ) datasetsHashes; 65 # Additional cross compilation related properties that scipy reads in scipy/meson.build 66 crossFileScipy = writeText "cross-file-scipy.conf" '' 67 [properties] 68 numpy-include-dir = '${numpy.coreIncludeDir}' 69 pythran-include-dir = '${pythran}/${python.sitePackages}/pythran' 70 host-python-path = '${python.interpreter}' 71 host-python-version = '${python.pythonVersion}' 72 ''; 73in 74buildPythonPackage { 75 inherit pname version; 76 pyproject = true; 77 78 src = fetchFromGitHub { 79 owner = "scipy"; 80 repo = "scipy"; 81 tag = "v${version}"; 82 hash = srcHash; 83 fetchSubmodules = true; 84 }; 85 86 patches = [ 87 # Helps with cross compilation, see https://github.com/scipy/scipy/pull/18167 88 (fetchpatch { 89 url = "https://github.com/scipy/scipy/commit/dd50ac9d98dbb70625333a23e3a90e493228e3be.patch"; 90 hash = "sha256-Vf6/hhwu6X5s8KWhq8bUZKtSkdVu/GtEpGtj8Olxe7s="; 91 excludes = [ "doc/source/dev/contributor/meson_advanced.rst" ]; 92 }) 93 ]; 94 # A NOTE regarding the Numpy version relaxing: Both Numpy versions 1.x & 95 # 2.x are supported. However upstream wants to always build with Numpy 2, 96 # and with it to still be able to run with a Numpy 1 or 2. We insist to 97 # perform this substitution even though python3.pkgs.numpy is of version 2 98 # nowadays, because our ecosystem unfortunately doesn't allow easily 99 # separating runtime and build-system dependencies. See also: 100 # 101 # https://discourse.nixos.org/t/several-comments-about-priorities-and-new-policies-in-the-python-ecosystem/51790 102 # 103 # Being able to build (& run) with Numpy 1 helps for python environments 104 # that override globally the `numpy` attribute to point to `numpy_1`. 105 postPatch = '' 106 substituteInPlace pyproject.toml \ 107 --replace-fail "numpy>=2.0.0,<2.5" numpy 108 ''; 109 110 build-system = 111 [ 112 cython 113 gfortran 114 meson-python 115 nukeReferences 116 pythran 117 pkg-config 118 setuptools 119 ] 120 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 121 # Minimal version required according to: 122 # https://github.com/scipy/scipy/blob/v1.14.0/scipy/meson.build#L185-L188 123 (xcbuild.override { 124 sdkVer = "13.3"; 125 }) 126 ]; 127 128 buildInputs = [ 129 blas 130 lapack 131 pybind11 132 pooch 133 xsimd 134 ]; 135 136 dependencies = [ numpy ]; 137 138 __darwinAllowLocalNetworking = true; 139 140 nativeCheckInputs = [ 141 hypothesis 142 pytestCheckHook 143 pytest-xdist 144 ]; 145 146 disabledTests = 147 [ 148 "test_cumulative_simpson_against_simpson_with_default_dx" 149 # https://github.com/scipy/scipy/issues/22789 150 "test_funcs" 151 ] 152 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [ 153 # The following tests are broken on aarch64-darwin with newer compilers and library versions. 154 # See https://github.com/scipy/scipy/issues/18308 155 "test_a_b_neg_int_after_euler_hypergeometric_transformation" 156 "test_dst4_definition_ortho" 157 "test_load_mat4_le" 158 "hyp2f1_test_case47" 159 "hyp2f1_test_case3" 160 "test_uint64_max" 161 "test_large_m4" # https://github.com/scipy/scipy/issues/22466 162 ]; 163 164 doCheck = !(stdenv.hostPlatform.isx86_64 && stdenv.hostPlatform.isDarwin); 165 166 preConfigure = 167 '' 168 # Helps parallelization a bit 169 export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES 170 # We download manually the datasets and this variable tells the pooch 171 # library where these files are cached. See also: 172 # https://github.com/scipy/scipy/pull/18518#issuecomment-1562350648 And at: 173 # https://github.com/scipy/scipy/pull/17965#issuecomment-1560759962 174 export XDG_CACHE_HOME=$PWD; export HOME=$(mktemp -d); mkdir scipy-data 175 '' 176 + (lib.concatStringsSep "\n" ( 177 lib.mapAttrsToList ( 178 d: dpath: 179 # Actually copy the datasets 180 "cp ${dpath} scipy-data/${d}.dat" 181 ) datasets 182 )); 183 184 mesonFlags = [ 185 "-Dblas=${blas.pname}" 186 "-Dlapack=${lapack.pname}" 187 # We always run what's necessary for cross compilation, which is passing to 188 # meson the proper cross compilation related arguments. See also: 189 # https://docs.scipy.org/doc/scipy/building/cross_compilation.html 190 "--cross-file=${crossFileScipy}" 191 ]; 192 193 # disable stackprotector on aarch64-darwin for now 194 # 195 # build error: 196 # 197 # /private/tmp/nix-build-python3.9-scipy-1.6.3.drv-0/ccDEsw5U.s:109:15: error: index must be an integer in range [-256, 255]. 198 # 199 # ldr x0, [x0, ___stack_chk_guard];momd 200 # 201 hardeningDisable = lib.optionals (stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isDarwin) [ 202 "stackprotector" 203 ]; 204 205 # remove references to dev dependencies 206 postInstall = '' 207 nuke-refs $out/${python.sitePackages}/scipy/__config__.py 208 rm $out/${python.sitePackages}/scipy/__pycache__/__config__.*.opt-1.pyc 209 ''; 210 211 preCheck = '' 212 export OMP_NUM_THREADS=$(( $NIX_BUILD_CORES / 4 )) 213 cd $out 214 ''; 215 216 requiredSystemFeatures = [ "big-parallel" ]; # the tests need lots of CPU time 217 218 passthru = { 219 inherit blas; 220 updateScript = 221 [ 222 ./update.sh 223 # Pass it this file name as argument 224 (builtins.unsafeGetAttrPos "pname" python.pkgs.scipy).file 225 ] 226 # Pass it the names of the datasets to update their hashes 227 ++ (builtins.attrNames datasetsHashes); 228 tests = { 229 inherit sage; 230 }; 231 }; 232 233 SCIPY_USE_G77_ABI_WRAPPER = 1; 234 235 meta = { 236 changelog = "https://github.com/scipy/scipy/releases/tag/v${version}"; 237 description = "SciPy (pronounced 'Sigh Pie') is open-source software for mathematics, science, and engineering"; 238 downloadPage = "https://github.com/scipy/scipy"; 239 homepage = "https://www.scipy.org/"; 240 license = lib.licenses.bsd3; 241 maintainers = with lib.maintainers; [ doronbehar ]; 242 }; 243}