From 670ac5606ce26f56a46f2b63f54a9e59b13f4f6a Mon Sep 17 00:00:00 2001
From: SomeoneSerge <else@someonex.net>
Date: Sun, 28 Jul 2024 16:50:30 +0000
Subject: [PATCH] faiss: mv test.pytest to python3Packages.test, fix eval

---
 .../libraries/science/math/faiss/default.nix  |  4 ++-
 .../python-modules/faiss/default.nix          |  9 +++++++
 .../faiss/pytest.nix}                         | 25 +++++++++++--------
 3 files changed, 26 insertions(+), 12 deletions(-)
 rename pkgs/development/{libraries/science/math/faiss/tests.nix => python-modules/faiss/pytest.nix} (61%)

diff --git a/pkgs/development/libraries/science/math/faiss/default.nix b/pkgs/development/libraries/science/math/faiss/default.nix
index 5ef390b2e1ff..9d0dea3ff6a1 100644
--- a/pkgs/development/libraries/science/math/faiss/default.nix
+++ b/pkgs/development/libraries/science/math/faiss/default.nix
@@ -137,7 +137,9 @@ stdenv.mkDerivation {
           ''
             demo_ivfpq_indexing && touch $out
           '';
-    } // lib.optionalAttrs pythonSupport { pytest = pythonPackages.callPackage ./tests.nix { }; };
+      pythonFaiss = pythonPackages.faiss;
+      pytest = pythonPackages.faiss.tests.pytest;
+    };
   };
 
   meta = with lib; {
diff --git a/pkgs/development/python-modules/faiss/default.nix b/pkgs/development/python-modules/faiss/default.nix
index 06ff4a4563ee..f6eee8cc5e32 100644
--- a/pkgs/development/python-modules/faiss/default.nix
+++ b/pkgs/development/python-modules/faiss/default.nix
@@ -1,6 +1,7 @@
 {
   lib,
   buildPythonPackage,
+  callPackage,
   faiss-build,
   numpy,
   packaging,
@@ -39,6 +40,14 @@ buildPythonPackage {
 
   pythonImportsCheck = [ "faiss" ];
 
+  passthru = {
+    inherit (faiss-build) cudaSupport cudaPackages pythonSupport;
+
+    tests = {
+      pytest = callPackage ./pytest.nix { inherit faiss-build; };
+    };
+  };
+
   meta = lib.pipe (faiss-build.meta or { }) [
     (lib.flip builtins.removeAttrs [ "mainProgram" ])
     (m: m // { description = "Bindings for faiss, the similarity search library"; })
diff --git a/pkgs/development/libraries/science/math/faiss/tests.nix b/pkgs/development/python-modules/faiss/pytest.nix
similarity index 61%
rename from pkgs/development/libraries/science/math/faiss/tests.nix
rename to pkgs/development/python-modules/faiss/pytest.nix
index 858a980bfeaf..b90ee9c244c6 100644
--- a/pkgs/development/libraries/science/math/faiss/tests.nix
+++ b/pkgs/development/python-modules/faiss/pytest.nix
@@ -1,8 +1,10 @@
-{ lib
-, buildPythonPackage
-, faiss
-, scipy
-, pytestCheckHook
+{
+  lib,
+  buildPythonPackage,
+  faiss,
+  faiss-build,
+  scipy,
+  pytestCheckHook,
 }:
 
 assert faiss.pythonSupport;
@@ -13,15 +15,13 @@ buildPythonPackage {
 
   format = "other";
 
-  src = "${faiss.src}/tests";
+  src = "${faiss-build.src}/tests";
 
   dontBuild = true;
   dontInstall = true;
 
   # Tests that need GPUs and would fail in the sandbox
-  disabledTestPaths = lib.optionals faiss.cudaSupport [
-    "test_contrib.py"
-  ];
+  disabledTestPaths = lib.optionals faiss.cudaSupport [ "test_contrib.py" ];
 
   disabledTests = [
     # https://github.com/facebookresearch/faiss/issues/2836
@@ -32,6 +32,9 @@ buildPythonPackage {
     faiss
     pytestCheckHook
     scipy
-  ] ++
-  faiss.extra-requires.all;
+  ];
+
+  meta = faiss.meta // {
+    description = "Faiss test suite";
+  };
 }