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