nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchurl,
5 writeTextFile,
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 boost189,
32 qhull,
33
34 # dependencies
35 numpy,
36
37 # tests
38 hypothesis,
39 pytestCheckHook,
40 pytest-xdist,
41
42 # Reverse dependency
43 sage,
44}:
45
46buildPythonPackage (finalAttrs: {
47 pname = "scipy";
48 version = "1.17.0";
49 pyproject = true;
50
51 src = fetchFromGitHub {
52 owner = "scipy";
53 repo = "scipy";
54 tag = "v${finalAttrs.version}";
55 hash = "sha256-bDcM/RGfce/ZTYpTBNpKmX/7rXDqQs7rYkAmeXtzkZk=";
56 fetchSubmodules = true;
57 };
58
59 patches = [
60 # Helps with cross compilation, see https://github.com/scipy/scipy/pull/18167
61 (fetchpatch {
62 url = "https://github.com/scipy/scipy/commit/dd50ac9d98dbb70625333a23e3a90e493228e3be.patch";
63 hash = "sha256-Vf6/hhwu6X5s8KWhq8bUZKtSkdVu/GtEpGtj8Olxe7s=";
64 excludes = [ "doc/source/dev/contributor/meson_advanced.rst" ];
65 })
66 ];
67
68 build-system = [
69 cython
70 gfortran
71 meson-python
72 nukeReferences
73 pythran
74 pkg-config
75 setuptools
76 ]
77 ++ lib.optionals stdenv.hostPlatform.isDarwin [
78 # Minimal version required according to:
79 # https://github.com/scipy/scipy/blob/v1.16.0/scipy/meson.build#L238-L244
80 (xcbuild.override {
81 sdkVer = "13.3";
82 })
83 ];
84
85 buildInputs = [
86 blas
87 lapack
88 pybind11
89 pooch
90 xsimd
91 boost189
92 qhull
93 ];
94
95 dependencies = [ numpy ];
96
97 __darwinAllowLocalNetworking = true;
98
99 nativeCheckInputs = [
100 hypothesis
101 pytestCheckHook
102 pytest-xdist
103 ];
104
105 disabledTests =
106 lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
107 # The following tests are broken on aarch64-darwin with newer compilers and library versions.
108 # See https://github.com/scipy/scipy/issues/18308
109 "test_a_b_neg_int_after_euler_hypergeometric_transformation"
110 "test_dst4_definition_ortho"
111 "test_load_mat4_le"
112 "hyp2f1_test_case47"
113 "hyp2f1_test_case3"
114 "test_uint64_max"
115 "test_large_m4" # https://github.com/scipy/scipy/issues/22466
116 ]
117 ++ lib.optionals (stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian) [
118 # https://github.com/scipy/scipy/issues/24090
119 "test_cython_api"
120 "test_distance_transform_cdt05"
121 "test_eval_chebyt_gh20129"
122 "test_hyp0f1"
123 "test_hyp0f1_gh5764"
124 "test_simple_det_shapes_real_complex"
125 ]
126 ++ lib.optionals (python.isPy311) [
127 # https://github.com/scipy/scipy/issues/22789 Observed only with Python 3.11
128 "test_funcs"
129 ];
130
131 doCheck = !(stdenv.hostPlatform.isx86_64 && stdenv.hostPlatform.isDarwin);
132
133 preConfigure = ''
134 # Helps parallelization a bit
135 export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES
136 # We download manually the datasets and this variable tells the pooch
137 # library where these files are cached. See also:
138 # https://github.com/scipy/scipy/pull/18518#issuecomment-1562350648 And at:
139 # https://github.com/scipy/scipy/pull/17965#issuecomment-1560759962
140 export XDG_CACHE_HOME=$PWD; export HOME=$(mktemp -d); mkdir scipy-data
141 ''
142 + (lib.concatStringsSep "\n" (
143 lib.mapAttrsToList (
144 d: dpath:
145 # Actually copy the datasets
146 "cp ${dpath} scipy-data/${d}.dat"
147 ) finalAttrs.finalPackage.passthru.datasets
148 ));
149
150 mesonFlags = [
151 "-Dblas=${blas.pname}"
152 "-Dlapack=${lapack.pname}"
153 # We always run what's necessary for cross compilation, which is passing to
154 # meson the proper cross compilation related arguments. See also:
155 # https://docs.scipy.org/doc/scipy/building/cross_compilation.html
156 "--cross-file=${finalAttrs.finalPackage.passthru.crossFile}"
157 "-Duse-system-libraries=all"
158 ];
159
160 # disable stackprotector on aarch64-darwin for now
161 #
162 # build error:
163 #
164 # /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].
165 #
166 # ldr x0, [x0, ___stack_chk_guard];momd
167 #
168 hardeningDisable = lib.optionals (stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isDarwin) [
169 "stackprotector"
170 ];
171
172 # remove references to dev dependencies
173 postInstall = ''
174 nuke-refs $out/${python.sitePackages}/scipy/__config__.py
175 rm $out/${python.sitePackages}/scipy/__pycache__/__config__.*.opt-1.pyc
176 '';
177
178 preCheck = ''
179 export OMP_NUM_THREADS=$(( $NIX_BUILD_CORES / 4 ))
180 if [ $OMP_NUM_THREADS -eq 0 ]; then
181 export OMP_NUM_THREADS=1
182 fi
183
184 cd $out
185 '';
186
187 requiredSystemFeatures = [ "big-parallel" ]; # the tests need lots of CPU time
188
189 passthru = {
190 inherit blas;
191 tests = {
192 inherit sage;
193 };
194 # NOTE: Every once in a while, these hashes might need an update. Use:
195 #
196 # nix build -Lf. --rebuild python3.pkgs.scipy.passthru.datasets
197 #
198 # To verify the hashes are correct.
199 datasetsHashes = {
200 ascent = "sha256-A84STBr8iA+HtV9rBhEQ4uHpOWeRhPVhTjjazGwZV+I=";
201 ecg = "sha256-8grTNl+5t/hF0OXEi2/mcIE3fuRmw6Igt/afNciVi68=";
202 face = "sha256-nYsLTQgTE+K0hXSMdwRy5ale0XOBRog9hMcDBJPoKIY=";
203 };
204 datasets = lib.mapAttrs (
205 d: hash:
206 fetchurl {
207 url = "https://raw.githubusercontent.com/scipy/dataset-${d}/main/${d}.dat";
208 inherit hash;
209 }
210 ) finalAttrs.finalPackage.passthru.datasetsHashes;
211 # Additional cross compilation related properties that scipy reads in scipy/meson.build
212 buildConfig = {
213 properties = {
214 numpy-include-dir = numpy.coreIncludeDir;
215 pythran-include-dir = "${pythran}/${python.sitePackages}/pythran";
216 host-python-path = python.interpreter;
217 host-python-version = python.pythonVersion;
218 };
219 };
220 crossFile = writeTextFile {
221 name = "cross-file-scipy.conf";
222 text = lib.generators.toINI {
223 mkKeyValue = lib.generators.mkKeyValueDefault {
224 mkValueString = v: "'${v}'";
225 } " = ";
226 } finalAttrs.finalPackage.passthru.buildConfig;
227 };
228 };
229
230 SCIPY_USE_G77_ABI_WRAPPER = 1;
231
232 meta = {
233 changelog = "https://github.com/scipy/scipy/releases/tag/v${finalAttrs.version}";
234 description = "SciPy (pronounced 'Sigh Pie') is open-source software for mathematics, science, and engineering";
235 downloadPage = "https://github.com/scipy/scipy";
236 homepage = "https://www.scipy.org/";
237 license = lib.licenses.bsd3;
238 maintainers = with lib.maintainers; [ doronbehar ];
239 };
240})