summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ve/vectorcode/package.nix
blob: fe3da8ac47bef353b797728b66e1b7c8728ec03f (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
{
  lib,
  cargo,
  fetchFromGitHub,
  installShellFiles,
  pkg-config,
  protobuf,
  python3,
  rustc,
  rustPlatform,
  versionCheckHook,

  lspSupport ? true,
}:

let
  python = python3.override {
    packageOverrides = self: super: {
      # https://github.com/Davidyz/VectorCode/pull/36
      chromadb = super.chromadb.overridePythonAttrs (old: rec {
        version = "0.6.3";
        src = fetchFromGitHub {
          owner = "chroma-core";
          repo = "chroma";
          tag = version;
          hash = "sha256-yvAX8buETsdPvMQmRK5+WFz4fVaGIdNlfhSadtHwU5U=";
        };
        cargoDeps = rustPlatform.fetchCargoVendor {
          pname = "chromadb";
          inherit version src;
          hash = "sha256-lHRBXJa/OFNf4x7afEJw9XcuDveTBIy3XpQ3+19JXn4=";
        };
        pythonRelaxDeps = [ "chroma-hnswlib" ];
        postPatch = null;
        build-system = with self; [
          setuptools
          setuptools-scm
        ];
        nativeBuildInputs = [
          cargo
          pkg-config
          protobuf
          rustc
          rustPlatform.cargoSetupHook
        ];
        dependencies = old.dependencies ++ [
          self.chroma-hnswlib
        ];

        # The base package disables additional tests, so explicitly override
        disabledTests = [
          # Tests are flaky / timing sensitive
          "test_fastapi_server_token_authn_allows_when_it_should_allow"
          "test_fastapi_server_token_authn_rejects_when_it_should_reject"

          # Issue with event loop
          "test_http_client_bw_compatibility"

          # httpx ReadError
          "test_not_existing_collection_delete"
        ];

        disabledTestPaths = [
          # Tests require network access
          "chromadb/test/auth/test_simple_rbac_authz.py"
          "chromadb/test/db/test_system.py"
          "chromadb/test/ef/test_default_ef.py"
          "chromadb/test/property/"
          "chromadb/test/property/test_cross_version_persist.py"
          "chromadb/test/stress/"
          "chromadb/test/test_api.py"

          # httpx failures
          "chromadb/test/api/test_delete_database.py"

          # Cannot be loaded by pytest without path hacks (fixed in 1.0.0)
          "chromadb/test/test_logservice.py"
          "chromadb/test/proto/test_utils.py"
          "chromadb/test/segment/distributed/test_protobuf_translation.py"

          # Hypothesis FailedHealthCheck due to nested @given tests
          "chromadb/test/cache/test_cache.py"

          # Tests fail when running in parallel.
          # E.g. when building the building python 3.12 and 3.13 versions simultaneously.
          # ValueError: An instance of Chroma already exists for ephemeral with different settings
          "chromadb/test/test_chroma.py"
          "chromadb/test/test_client.py"
          "chromadb/test/ef/test_multimodal_ef.py"

          # sqlite3.OperationalError: no such table: migrations
          "chromadb/test/db/test_migrations.py::test_migrations[sqlite]"
        ];
      });
      lsprotocol = self.lsprotocol_2023;
      pygls = self.pygls_1;
    };
  };
in
python.pkgs.buildPythonApplication rec {
  pname = "vectorcode";
  version = "0.7.20";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "Davidyz";
    repo = "VectorCode";
    tag = version;
    hash = "sha256-RU9WnKuPaxDnPW5MQyrxPEw7ufMcVNxSRyJ5QvrzoVs=";
  };

  build-system = with python.pkgs; [
    pdm-backend
  ];

  pythonRelaxDeps = [
    "posthog"
    "wheel"
  ];
  dependencies =
    with python.pkgs;
    [
      chromadb
      colorlog
      httpx
      json5
      numpy
      pathspec
      psutil
      pygments
      python-dotenv
      sentence-transformers
      shtab
      tabulate
      transformers
      tree-sitter
      tree-sitter-language-pack
    ]
    ++ lib.optionals lspSupport optional-dependencies.lsp;

  optional-dependencies = with python.pkgs; {
    intel = [
      openvino
      optimum
    ];
    legacy = [
      numpy
      torch
      transformers
    ];
    lsp = [
      lsprotocol
      pygls
    ];
    mcp = [
      mcp
      pydantic
    ];
  };

  nativeBuildInputs = [
    installShellFiles
  ];

  postInstall = ''
    $out/bin/vectorcode --print-completion=bash >vectorcode.bash
    $out/bin/vectorcode --print-completion=zsh >vectorcode.zsh
    installShellCompletion vectorcode.{bash,zsh}
  '';

  makeWrapperArgs = [
    "--prefix"
    "PYTHONPATH"
    ":"
    "$PYTHONPATH"
  ];

  pythonImportsCheck = [ "vectorcode" ];

  nativeCheckInputs = [
    versionCheckHook
  ]
  ++ (with python.pkgs; [
    mcp
    pygls
    pytest-asyncio
    pytestCheckHook
  ]);
  versionCheckProgramArg = "version";

  disabledTests = [
    # Require internet access
    "test_build_query_results_chunk_mode_success"
    "test_chunked_add"
    "test_chunked_add_empty_file"
    "test_chunked_add_truncated"
    "test_chunked_add_update_existing"
    "test_chunked_add_with_existing"
    "test_get_embedding_function"
    "test_get_embedding_function_fallback"
    "test_get_query_reranker_initialisation_error"
    "test_get_query_result_chunks_with_query_exclude"
    "test_get_query_result_files_include_chunk"
    "test_get_query_result_files_multiple_queries"
    "test_get_query_result_files_query_error"
    "test_get_query_result_files_with_query_exclude"
    "test_get_reranker"
    "test_query_tool_success"
    "test_supported_rerankers_initialization"
    # tree-sitter-language-pack 1.x.x raises LanguageNotFoundError for unknown
    # languages here, while this test still expects LookupError.
    "test_treesitter_chunker_parser_from_config_no_parser_found_error"
  ];

  passthru = {
    # Expose these overridden inputs for debugging
    inherit python;
    inherit (python.pkgs) chromadb;
  };

  meta = {
    description = "Code repository indexing tool to supercharge your LLM experience";
    homepage = "https://github.com/Davidyz/VectorCode";
    changelog = "https://github.com/Davidyz/VectorCode/releases/tag/${src.tag}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ GaetanLepage ];
    mainProgram = "vectorcode";
    badPlatforms = [
      # Error in cpuinfo: failed to parse the list of possible processors in /sys/devices/system/cpu/possible
      # Error in cpuinfo: failed to parse the list of present processors in /sys/devices/system/cpu/present
      # Error in cpuinfo: failed to parse both lists of possible and present processors
      # terminate called after throwing an instance of 'onnxruntime::OnnxRuntimeException'
      #   what():  /build/source/include/onnxruntime/core/common/logging/logging.h:371 static const onnxruntime::logging::Logger& onnxruntime::logging::LoggingManager::DefaultLogger() Attempt to use DefaultLogger but none has been registered.
      #
      # Since 0.7.4, disabling `pythonImportsCheck` and `pytestCheckPhase` is not enough anymore.
      # The error above happens at the end of `pypaInstallPhase`.
      "aarch64-linux"
    ];
  };
}