Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at github-to-sqlite-beautifulsoup4 134 lines 3.9 kB view raw
1{ lib 2, stdenv 3, fetchPypi 4, fetchpatch 5, python 6, buildPythonPackage 7, gfortran 8, hypothesis 9, pytest 10, typing-extensions 11, blas 12, lapack 13, writeTextFile 14, cython 15, pythonOlder 16}: 17 18assert (!blas.isILP64) && (!lapack.isILP64); 19 20let 21 cfg = writeTextFile { 22 name = "site.cfg"; 23 text = lib.generators.toINI {} { 24 ${blas.implementation} = { 25 include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; 26 library_dirs = "${blas}/lib:${lapack}/lib"; 27 runtime_library_dirs = "${blas}/lib:${lapack}/lib"; 28 libraries = "lapack,lapacke,blas,cblas"; 29 }; 30 lapack = { 31 include_dirs = "${lib.getDev lapack}/include"; 32 library_dirs = "${lapack}/lib"; 33 runtime_library_dirs = "${lapack}/lib"; 34 }; 35 blas = { 36 include_dirs = "${lib.getDev blas}/include"; 37 library_dirs = "${blas}/lib"; 38 runtime_library_dirs = "${blas}/lib"; 39 }; 40 }; 41 }; 42in buildPythonPackage rec { 43 pname = "numpy"; 44 version = "1.25.1"; 45 format = "setuptools"; 46 disabled = pythonOlder "3.7"; 47 48 src = fetchPypi { 49 inherit pname version; 50 extension = "tar.gz"; 51 hash = "sha256-mjqfOmFIDMCGEXtCaovYaGnCE/xAcuYG8BxOS2brkr8="; 52 }; 53 54 patches = [ 55 # f2py.f90mod_rules generates code with invalid function pointer conversions, which are 56 # clang 16 makes an error by default. 57 (fetchpatch { 58 url = "https://github.com/numpy/numpy/commit/609fee4324f3521d81a3454f5fcc33abb0d3761e.patch"; 59 hash = "sha256-6Dbmf/RWvQJPTIjvchVaywHGcKCsgap/0wAp5WswuCo="; 60 }) 61 62 # Disable `numpy/core/tests/test_umath.py::TestComplexFunctions::test_loss_of_precision[complex256]` 63 # on x86_64-darwin because it fails under Rosetta 2 due to issues with trig functions and 64 # 80-bit long double complex numbers. 65 ./disable-failing-long-double-test-Rosetta-2.patch 66 ] 67 # We patch cpython/distutils to fix https://bugs.python.org/issue1222585 68 # Patching of numpy.distutils is needed to prevent it from undoing the 69 # patch to distutils. 70 ++ lib.optionals python.hasDistutilsCxxPatch [ 71 ./numpy-distutils-C++.patch 72 ]; 73 74 postPatch = '' 75 # fails with multiple errors because we are not using the pinned setuptools version 76 # see https://github.com/numpy/numpy/blob/v1.25.0/pyproject.toml#L7 77 # error: option --single-version-externally-managed not recognized 78 # TypeError: dist must be a Distribution instance 79 rm numpy/core/tests/test_cython.py 80 ''; 81 82 nativeBuildInputs = [ gfortran cython ]; 83 buildInputs = [ blas lapack ]; 84 85 # Causes `error: argument unused during compilation: '-fno-strict-overflow'` due to `-Werror`. 86 hardeningDisable = lib.optionals stdenv.cc.isClang [ "strictoverflow" ]; 87 88 # we default openblas to build with 64 threads 89 # if a machine has more than 64 threads, it will segfault 90 # see https://github.com/xianyi/OpenBLAS/issues/2993 91 preConfigure = '' 92 sed -i 's/-faltivec//' numpy/distutils/system_info.py 93 export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES 94 export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES)) 95 ''; 96 97 preBuild = '' 98 ln -s ${cfg} site.cfg 99 ''; 100 101 enableParallelBuilding = true; 102 103 nativeCheckInputs = [ 104 pytest 105 hypothesis 106 typing-extensions 107 ]; 108 109 checkPhase = '' 110 runHook preCheck 111 pushd "$out" 112 ${python.interpreter} -c 'import numpy, sys; sys.exit(numpy.test("fast", verbose=10) is False)' 113 popd 114 runHook postCheck 115 ''; 116 117 passthru = { 118 # just for backwards compatibility 119 blas = blas.provider; 120 blasImplementation = blas.implementation; 121 inherit cfg; 122 }; 123 124 # Disable test 125 # - test_large_file_support: takes a long time and can cause the machine to run out of disk space 126 NOSE_EXCLUDE="test_large_file_support"; 127 128 meta = { 129 description = "Scientific tools for Python"; 130 homepage = "https://numpy.org/"; 131 license = lib.licenses.bsd3; 132 maintainers = with lib.maintainers; [ fridh ]; 133 }; 134}