about summary refs log tree commit diff
path: root/pkgs/development/python-modules/numba/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/python-modules/numba/default.nix')
-rw-r--r--pkgs/development/python-modules/numba/default.nix127
1 files changed, 79 insertions, 48 deletions
diff --git a/pkgs/development/python-modules/numba/default.nix b/pkgs/development/python-modules/numba/default.nix
index 2e219e018dd14..18bd264c5d76f 100644
--- a/pkgs/development/python-modules/numba/default.nix
+++ b/pkgs/development/python-modules/numba/default.nix
@@ -8,14 +8,16 @@
   buildPythonPackage,
   setuptools,
   numpy,
+  numpy_2,
   llvmlite,
   libcxx,
   importlib-metadata,
+  fetchpatch,
   substituteAll,
   runCommand,
-  symlinkJoin,
   writers,
   numba,
+  pytestCheckHook,
 
   config,
 
@@ -26,15 +28,15 @@
 
   # CUDA flags:
   cudaSupport ? config.cudaSupport,
+  testsWithoutSandbox ? false,
+  doFullCheck ? false,
 }:
 
 let
   cudatoolkit = cudaPackages.cuda_nvcc;
 in
 buildPythonPackage rec {
-  # Using an untagged version, with numpy 1.25 support, when it's released
-  # also drop the versioneer patch in postPatch
-  version = "0.59.1";
+  version = "0.61.0dev0";
   pname = "numba";
   pyproject = true;
 
@@ -55,8 +57,18 @@ buildPythonPackage rec {
     # that upstream relies on those strings to be valid, that's why we don't
     # use `forceFetchGit = true;`.` If in the future we'll observe the hash
     # changes too often, we can always use forceFetchGit, and inject the
-    # relevant strings ourselves, using `sed` commands, in extraPostFetch.
-    hash = "sha256-4udpgLLHbHNtxPiYVkj+gxAjTWV3ClZOv98Y313/qbc=";
+    # relevant strings ourselves, using `substituteInPlace`, in postFetch.
+    hash = "sha256-KF9YQ6/FIfUQTJCAMgfIqnb/D8mdMbCC/tJvfYlSkgI=";
+    # TEMPORARY: The way upstream knows it's source version is explained above,
+    # and without this upstream sets the version in ${python.sitePackages} as
+    # 0.61.0dev0, which causes dependent packages fail to find a valid
+    # version of numba.
+    postFetch = ''
+      substituteInPlace $out/numba/_version.py \
+        --replace-fail \
+          'git_refnames = " (tag: ${version})"' \
+          'git_refnames = " (tag: 0.61.0, release0.61)"'
+    '';
   };
 
   postPatch = ''
@@ -66,44 +78,65 @@ buildPythonPackage rec {
         "dldir = [ '${addDriverRunpath.driverLink}/lib', "
   '';
 
-  env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
+  env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
 
-  nativeBuildInputs =
-    [ numpy ]
-    ++ lib.optionals cudaSupport [
-      autoAddDriverRunpath
-      cudaPackages.cuda_nvcc
-    ];
+  build-system = [
+    setuptools
+    numpy
+  ];
+
+  nativeBuildInputs = lib.optionals cudaSupport [
+    autoAddDriverRunpath
+    cudaPackages.cuda_nvcc
+  ];
 
   buildInputs = lib.optionals cudaSupport [ cudaPackages.cuda_cudart ];
 
-  propagatedBuildInputs = [
+  dependencies = [
     numpy
     llvmlite
     setuptools
   ] ++ lib.optionals (pythonOlder "3.9") [ importlib-metadata ];
 
-  patches = lib.optionals cudaSupport [
-    (substituteAll {
-      src = ./cuda_path.patch;
-      cuda_toolkit_path = cudatoolkit;
-      cuda_toolkit_lib_path = lib.getLib cudatoolkit;
-    })
+  patches =
+    [
+      (fetchpatch {
+        # TODO Remove at the next release of numba (>0.60.0)
+        # https://github.com/numba/numba/pull/9683
+        name = "fix-numpy-2-0-1-compat";
+        url = "https://github.com/numba/numba/commit/afb3d168efa713c235d1bb4586722ad6e5dbb0c1.patch";
+        hash = "sha256-WB+XKxsF2r5ZdgW2Yrg9HutpgufBfk48i+5YLQnKLFY=";
+      })
+    ]
+    ++ lib.optionals cudaSupport [
+      (substituteAll {
+        src = ./cuda_path.patch;
+        cuda_toolkit_path = cudatoolkit;
+        cuda_toolkit_lib_path = lib.getLib cudatoolkit;
+      })
+    ];
+
+  nativeCheckInputs = [
+    pytestCheckHook
   ];
 
-  # run a smoke test in a temporary directory so that
-  # a) Python picks up the installed library in $out instead of the build files
-  # b) we have somewhere to put $HOME so some caching tests work
-  # c) it doesn't take 6 CPU hours for the full suite
-  checkPhase = ''
-    runHook preCheck
+  preCheck = ''
+    export HOME="$(mktemp -d)"
+    # https://github.com/NixOS/nixpkgs/issues/255262
+    cd $out
+  '';
 
-    pushd $(mktemp -d)
-    HOME=. ${python.interpreter} -m numba.runtests -m $NIX_BUILD_CORES numba.tests.test_usecases
-    popd
+  pytestFlagsArray = lib.optionals (!doFullCheck) [
+    # These are the most basic tests. Running all tests is too expensive, and
+    # some of them fail (also differently on different platforms), so it will
+    # be too hard to maintain such a `disabledTests` list.
+    "${python.sitePackages}/numba/tests/test_usecases.py"
+  ];
 
-    runHook postCheck
-  '';
+  disabledTestPaths = lib.optionals (!testsWithoutSandbox) [
+    # See NOTE near passthru.tests.withoutSandbox
+    "${python.sitePackages}/numba/cuda/tests"
+  ];
 
   pythonImportsCheck = [ "numba" ];
 
@@ -116,23 +149,21 @@ buildPythonPackage rec {
       '';
   passthru.tests = {
     # CONTRIBUTOR NOTE: numba also contains CUDA tests, though these cannot be run in
-    # this sandbox environment. Consider running similar commands to those below outside the
-    # sandbox manually if you have the appropriate hardware; support will be detected
-    # and the corresponding tests enabled automatically.
-    # Also, the full suite currently does not complete on anything but x86_64-linux.
-    fullSuite = runCommand "${pname}-test" { } ''
-      pushd $(mktemp -d)
-      # pip and python in $PATH is needed for the test suite to pass fully
-      PATH=${
-        python.withPackages (p: [
-          p.numba
-          p.pip
-        ])
-      }/bin:$PATH
-      HOME=$PWD python -m numba.runtests -m $NIX_BUILD_CORES
-      popd
-      touch $out # stop Nix from complaining no output was generated and failing the build
-    '';
+    # this sandbox environment. Consider building the derivation below with
+    # --no-sandbox to get a view of how many tests succeed outside the sandbox.
+    withoutSandbox = numba.override {
+      doFullCheck = true;
+      cudaSupport = true;
+      testsWithoutSandbox = true;
+    };
+    withSandbox = numba.override {
+      cudaSupport = false;
+      doFullCheck = true;
+      testsWithoutSandbox = false;
+    };
+    numpy_2 = numba.override {
+      numpy = numpy_2;
+    };
   };
 
   meta = with lib; {