From 63f6dbf24762f34252109cab6638996bf6475455 Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Sun, 28 Jul 2024 01:54:59 +0000 Subject: [PATCH] python3Packages.faiss: split into its own derivation --- .../libraries/science/math/faiss/default.nix | 27 +++-------- .../python-modules/faiss/default.nix | 46 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 10 ++-- 3 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 pkgs/development/python-modules/faiss/default.nix diff --git a/pkgs/development/libraries/science/math/faiss/default.nix b/pkgs/development/libraries/science/math/faiss/default.nix index d4e1eaa0bc13..e6b21542cbf8 100644 --- a/pkgs/development/libraries/science/math/faiss/default.nix +++ b/pkgs/development/libraries/science/math/faiss/default.nix @@ -44,7 +44,7 @@ in stdenv.mkDerivation { inherit pname version; - outputs = [ "out" "demos" ]; + outputs = [ "out" "demos" "dist" ]; src = fetchFromGitHub { owner = "facebookresearch"; @@ -67,28 +67,20 @@ stdenv.mkDerivation { addDriverRunpath ] ++ lib.optionals pythonSupport [ pythonPackages.python + pythonPackages.setuptools + pythonPackages.pip + pythonPackages.wheel ]; buildInputs = [ blas swig ] ++ lib.optionals pythonSupport [ - pythonPackages.setuptools - pythonPackages.pip - pythonPackages.wheel + pythonPackages.numpy ] ++ lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ] ++ lib.optionals cudaSupport cudaComponents; - propagatedBuildInputs = lib.optionals pythonSupport [ - pythonPackages.numpy - pythonPackages.packaging - ]; - - passthru.extra-requires.all = [ - pythonPackages.numpy - ]; - cmakeFlags = [ "-DFAISS_ENABLE_GPU=${if cudaSupport then "ON" else "OFF"}" "-DFAISS_ENABLE_PYTHON=${if pythonSupport then "ON" else "OFF"}" @@ -119,8 +111,8 @@ stdenv.mkDerivation { cp ./demos/demo_ivfpq_indexing $demos/bin/ fi '' + lib.optionalString pythonSupport '' - mkdir -p $out/${pythonPackages.python.sitePackages} - (cd faiss/python && python -m pip install dist/*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache) + mkdir "$dist" + cp faiss/python/dist/*.whl "$dist/" ''; postFixup = lib.optionalString (pythonSupport && cudaSupport) '' @@ -128,11 +120,6 @@ stdenv.mkDerivation { addDriverRunpath $demos/bin/* ''; - # Need buildPythonPackage for this one - # pythonImportsCheck = [ - # "faiss" - # ]; - passthru = { inherit cudaSupport cudaPackages pythonSupport; diff --git a/pkgs/development/python-modules/faiss/default.nix b/pkgs/development/python-modules/faiss/default.nix new file mode 100644 index 000000000000..06ff4a4563ee --- /dev/null +++ b/pkgs/development/python-modules/faiss/default.nix @@ -0,0 +1,46 @@ +{ + lib, + buildPythonPackage, + faiss-build, + numpy, + packaging, + setuptools, + pip, + wheel, +}: + +buildPythonPackage { + inherit (faiss-build) pname version; + pyproject = true; + + src = "${lib.getOutput "dist" faiss-build}"; + + postPatch = '' + mkdir dist + mv *.whl dist/ + ''; + + build-system = [ + setuptools + pip + wheel + ]; + + dependencies = [ + numpy + packaging + ]; + + # E.g. cuda libraries; needed because reference scanning + # can't see inside the wheels + inherit (faiss-build) buildInputs; + + dontBuild = true; + + pythonImportsCheck = [ "faiss" ]; + + 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/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 8d090e3a5173..8046bf0c3810 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -4161,10 +4161,12 @@ self: super: with self; { fairseq = callPackage ../development/python-modules/fairseq { }; - faiss = toPythonModule (pkgs.faiss.override { - pythonSupport = true; - pythonPackages = self; - }); + faiss = callPackage ../development/python-modules/faiss { + faiss-build = pkgs.faiss.override { + pythonSupport = true; + pythonPackages = self; + }; + }; fake-useragent = callPackage ../development/python-modules/fake-useragent { };