1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchPypi,
6 pythonOlder,
7 setuptools,
8 tree-sitter-python,
9 tree-sitter-rust,
10 tree-sitter-html,
11 tree-sitter-javascript,
12 tree-sitter-json,
13}:
14
15buildPythonPackage rec {
16 pname = "tree-sitter";
17 version = "0.25.0";
18 pyproject = true;
19
20 disabled = pythonOlder "3.10";
21
22 src = fetchPypi {
23 inherit pname version;
24 hash = "sha256-FciHdc8k2wZne6/mLfBYpkV9im3eZ7qkjdNyO5BeeaY=";
25 };
26
27 # see https://github.com/tree-sitter/py-tree-sitter/issues/330#issuecomment-2629403946
28 patches = lib.optionals (stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isLinux) [
29 ./segfault-patch.diff
30 ];
31
32 build-system = [ setuptools ];
33
34 nativeCheckInputs = [
35 tree-sitter-python
36 tree-sitter-rust
37 tree-sitter-html
38 tree-sitter-javascript
39 tree-sitter-json
40 ];
41
42 pythonImportsCheck = [ "tree_sitter" ];
43
44 preCheck = ''
45 # https://github.com/NixOS/nixpkgs/issues/255262#issuecomment-1721265871
46 rm -r tree_sitter
47 '';
48
49 disabledTests = [
50 # test fails in nix sandbox
51 "test_dot_graphs"
52 ];
53
54 meta = {
55 description = "Python bindings to the Tree-sitter parsing library";
56 homepage = "https://github.com/tree-sitter/py-tree-sitter";
57 changelog = "https://github.com/tree-sitter/py-tree-sitter/releases/tag/v${version}";
58 license = lib.licenses.mit;
59 maintainers = with lib.maintainers; [ fab ];
60 };
61}