at 23.05-pre 3.5 kB view raw
1{ lib 2, stdenv 3, pythonAtLeast 4, pythonOlder 5, fetchPypi 6, python 7, buildPythonPackage 8, setuptools 9, numpy 10, llvmlite 11, libcxx 12, importlib-metadata 13, substituteAll 14, runCommand 15, fetchpatch 16 17# CUDA-only dependencies: 18, addOpenGLRunpath ? null 19, cudaPackages ? {} 20 21# CUDA flags: 22, cudaSupport ? false 23}: 24 25let 26 inherit (cudaPackages) cudatoolkit; 27in buildPythonPackage rec { 28 version = "0.56.4"; 29 pname = "numba"; 30 format = "setuptools"; 31 disabled = pythonOlder "3.6" || pythonAtLeast "3.11"; 32 33 src = fetchPypi { 34 inherit pname version; 35 hash = "sha256-Mtn+9BLIFIPX7+DOts9NMxD96LYkqc7MoA95BXOslu4="; 36 }; 37 38 postPatch = '' 39 substituteInPlace setup.py \ 40 --replace "setuptools<60" "setuptools" 41 ''; 42 43 NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1"; 44 45 nativeBuildInputs = lib.optionals cudaSupport [ 46 addOpenGLRunpath 47 ]; 48 49 propagatedBuildInputs = [ 50 numpy 51 llvmlite 52 setuptools 53 ] ++ lib.optionals (pythonOlder "3.9") [ 54 importlib-metadata 55 ] ++ lib.optionals cudaSupport [ 56 cudatoolkit 57 cudatoolkit.lib 58 ]; 59 60 patches = [ 61 # fix failure in test_cache_invalidate (numba.tests.test_caching.TestCache) 62 # remove when upgrading past version 0.56 63 (fetchpatch { 64 name = "fix-test-cache-invalidate-readonly.patch"; 65 url = "https://github.com/numba/numba/commit/993e8c424055a7677b2755b184fc9e07549713b9.patch"; 66 hash = "sha256-IhIqRLmP8gazx+KWIyCxZrNLMT4jZT8CWD3KcH4KjOo="; 67 }) 68 ] ++ lib.optionals cudaSupport [ 69 (substituteAll { 70 src = ./cuda_path.patch; 71 cuda_toolkit_path = cudatoolkit; 72 cuda_toolkit_lib_path = cudatoolkit.lib; 73 }) 74 ]; 75 76 postFixup = lib.optionalString cudaSupport '' 77 find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do 78 addOpenGLRunpath "$lib" 79 patchelf --set-rpath "${cudatoolkit}/lib:${cudatoolkit.lib}/lib:$(patchelf --print-rpath "$lib")" "$lib" 80 done 81 ''; 82 83 # run a smoke test in a temporary directory so that 84 # a) Python picks up the installed library in $out instead of the build files 85 # b) we have somewhere to put $HOME so some caching tests work 86 # c) it doesn't take 6 CPU hours for the full suite 87 checkPhase = '' 88 runHook preCheck 89 90 pushd $(mktemp -d) 91 HOME=. ${python.interpreter} -m numba.runtests -m $NIX_BUILD_CORES numba.tests.test_usecases 92 popd 93 94 runHook postCheck 95 ''; 96 97 pythonImportsCheck = [ 98 "numba" 99 ]; 100 101 passthru.tests = { 102 # CONTRIBUTOR NOTE: numba also contains CUDA tests, though these cannot be run in 103 # this sandbox environment. Consider running similar commands to those below outside the 104 # sandbox manually if you have the appropriate hardware; support will be detected 105 # and the corresponding tests enabled automatically. 106 # Also, the full suite currently does not complete on anything but x86_64-linux. 107 fullSuite = runCommand "${pname}-test" {} '' 108 pushd $(mktemp -d) 109 # pip and python in $PATH is needed for the test suite to pass fully 110 PATH=${python.withPackages (p: [ p.numba p.pip ])}/bin:$PATH 111 HOME=$PWD python -m numba.runtests -m $NIX_BUILD_CORES 112 popd 113 touch $out # stop Nix from complaining no output was generated and failing the build 114 ''; 115 }; 116 117 meta = with lib; { 118 description = "Compiling Python code using LLVM"; 119 homepage = "https://numba.pydata.org/"; 120 license = licenses.bsd2; 121 maintainers = with maintainers; [ fridh ]; 122 }; 123}