summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/sqlite-vec/default.nix
blob: fa5786b24425fb404f306cd8c24e2856acc71ac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  lib,
  buildPythonPackage,
  fetchpatch,

  # build-system
  setuptools,
  setuptools-scm,

  # dependencies
  sqlite-vec-c, # alias for pkgs.sqlite-vec

  # optional dependencies
  numpy,

  # check inputs
  openai,
  pytestCheckHook,
}:

buildPythonPackage rec {
  inherit (sqlite-vec-c) pname version src;
  pyproject = true;

  # The actual source root is bindings/python but the patches
  # apply to the bindings directory.
  # This is a known issue, see https://discourse.nixos.org/t/how-to-apply-patches-with-sourceroot/59727
  sourceRoot = "${src.name}/bindings";

  patches = [
    (fetchpatch {
      # https://github.com/asg017/sqlite-vec/pull/233
      name = "add-python-build-files.patch";
      url = "https://github.com/asg017/sqlite-vec/commit/c1917deb11aa79dcac32440679345b93e13b1b86.patch";
      hash = "sha256-4/9QLKuM/1AbD8AQHwJ14rhWVYVc+MILvK6+tWwWQlw=";
      stripLen = 1;
    })
    (fetchpatch {
      # https://github.com/asg017/sqlite-vec/pull/233
      name = "add-python-test.patch";
      url = "https://github.com/asg017/sqlite-vec/commit/608972c9dcbfc7f4583e99fd8de6e5e16da11081.patch";
      hash = "sha256-8dfw7zs7z2FYh8DoAxurMYCDMOheg8Zl1XGcPw1A1BM=";
      stripLen = 1;
    })
  ];

  # Change into the proper directory for building, move `extra_init.py` into its proper location,
  # and supply the path to the library.
  postPatch = ''
    cd python
    mv extra_init.py sqlite_vec/
    substituteInPlace sqlite_vec/__init__.py \
      --replace-fail "@libpath@" "${lib.getLib sqlite-vec-c}/lib/"
  '';

  build-system = [
    setuptools
    setuptools-scm
  ];

  dependencies = [
    sqlite-vec-c
  ];

  optional-dependencies = {
    numpy = [
      numpy
    ];
  };

  nativeCheckInputs = [
    numpy
    openai
    pytestCheckHook
    sqlite-vec-c
  ];

  pythonImportsCheck = [ "sqlite_vec" ];

  meta = sqlite-vec-c.meta // {
    description = "Python bindings for sqlite-vec";
    maintainers = [ lib.maintainers.sarahec ];
  };
}