1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 fetchpatch,
6 pytestCheckHook,
7 pythonOlder,
8 setuptools,
9}:
10
11buildPythonPackage rec {
12 pname = "tree-sitter";
13 version = "0.21.1";
14 pyproject = true;
15
16 disabled = pythonOlder "3.7";
17
18 src = fetchFromGitHub {
19 owner = "tree-sitter";
20 repo = "py-tree-sitter";
21 rev = "refs/tags/v${version}";
22 hash = "sha256-U4ZdU0lxjZO/y0q20bG5CLKipnfpaxzV3AFR6fGS7m4=";
23 fetchSubmodules = true;
24 };
25
26 patches = [
27 # Replace distutils with setuptools, https://github.com/tree-sitter/py-tree-sitter/pull/214
28 (fetchpatch {
29 name = "replace-distutils.patch";
30 url = "https://github.com/tree-sitter/py-tree-sitter/commit/80d3cae493c4a47e49cc1d2ebab0a8eaf7617825.patch";
31 hash = "sha256-00coI8/COpYMiSflAECwh6yJCMJj/ucFEn18Npj2g+Q=";
32 })
33 ];
34
35 nativeBuildInputs = [ setuptools ];
36
37 nativeCheckInputs = [ pytestCheckHook ];
38
39 pythonImportsCheck = [ "tree_sitter" ];
40
41 preCheck = ''
42 rm -r tree_sitter
43 '';
44
45 meta = with lib; {
46 description = "Python bindings to the Tree-sitter parsing library";
47 homepage = "https://github.com/tree-sitter/py-tree-sitter";
48 changelog = "https://github.com/tree-sitter/py-tree-sitter/releases/tag/v${version}";
49 license = licenses.mit;
50 maintainers = with maintainers; [ fab ];
51 };
52}