at master 2.0 kB view raw
1{ 2 lib, 3 buildPythonPackage, 4 fetchpatch, 5 6 # build-system 7 setuptools, 8 setuptools-scm, 9 10 # dependencies 11 sqlite-vec-c, # alias for pkgs.sqlite-vec 12 13 # optional dependencies 14 numpy, 15 16 # check inputs 17 openai, 18 pytestCheckHook, 19}: 20 21buildPythonPackage rec { 22 inherit (sqlite-vec-c) pname version src; 23 pyproject = true; 24 25 # The actual source root is bindings/python but the patches 26 # apply to the bindings directory. 27 # This is a known issue, see https://discourse.nixos.org/t/how-to-apply-patches-with-sourceroot/59727 28 sourceRoot = "${src.name}/bindings"; 29 30 patches = [ 31 (fetchpatch { 32 # https://github.com/asg017/sqlite-vec/pull/233 33 name = "add-python-build-files.patch"; 34 url = "https://github.com/asg017/sqlite-vec/commit/c1917deb11aa79dcac32440679345b93e13b1b86.patch"; 35 hash = "sha256-4/9QLKuM/1AbD8AQHwJ14rhWVYVc+MILvK6+tWwWQlw="; 36 stripLen = 1; 37 }) 38 (fetchpatch { 39 # https://github.com/asg017/sqlite-vec/pull/233 40 name = "add-python-test.patch"; 41 url = "https://github.com/asg017/sqlite-vec/commit/608972c9dcbfc7f4583e99fd8de6e5e16da11081.patch"; 42 hash = "sha256-8dfw7zs7z2FYh8DoAxurMYCDMOheg8Zl1XGcPw1A1BM="; 43 stripLen = 1; 44 }) 45 ]; 46 47 # Change into the proper directory for building, move `extra_init.py` into its proper location, 48 # and supply the path to the library. 49 postPatch = '' 50 cd python 51 mv extra_init.py sqlite_vec/ 52 substituteInPlace sqlite_vec/__init__.py \ 53 --replace-fail "@libpath@" "${lib.getLib sqlite-vec-c}/lib/" 54 ''; 55 56 build-system = [ 57 setuptools 58 setuptools-scm 59 ]; 60 61 dependencies = [ 62 sqlite-vec-c 63 ]; 64 65 optional-dependencies = { 66 numpy = [ 67 numpy 68 ]; 69 }; 70 71 nativeCheckInputs = [ 72 numpy 73 openai 74 pytestCheckHook 75 sqlite-vec-c 76 ]; 77 78 pythonImportsCheck = [ "sqlite_vec" ]; 79 80 meta = sqlite-vec-c.meta // { 81 description = "Python bindings for sqlite-vec"; 82 maintainers = [ lib.maintainers.sarahec ]; 83 }; 84}