python3Packages.faiss: split into its own derivation

This commit is contained in:
Someone Serge 2024-07-28 01:54:59 +00:00
parent 7294dbfb17
commit 63f6dbf247
3 changed files with 59 additions and 24 deletions

View File

@ -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;

View File

@ -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"; })
];
}

View File

@ -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 { };