1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 setuptools,
6 cython,
7 tree-sitter,
8 pytestCheckHook,
9 python,
10}:
11
12buildPythonPackage rec {
13 pname = "tree-sitter-languages";
14 version = "1.10.2";
15 pyproject = true;
16
17 src = fetchFromGitHub {
18 owner = "grantjenks";
19 repo = "py-tree-sitter-languages";
20 rev = "v${version}";
21 hash = "sha256-wKU2c8QRBKFVFqg+DAeH5+cwm5jpDLmPZG3YBUsh/lM=";
22 # Use git, to also fetch tree-sitter repositories that upstream puts their
23 # hashes in the repository as well, in repos.txt.
24 forceFetchGit = true;
25 postFetch = ''
26 cd $out
27 substitute build.py get-repos.py \
28 --replace-fail "from tree_sitter import Language" "" \
29 --replace-fail 'print(f"{sys.argv[0]}: Building", languages_filename)' "exit(0)"
30 ${python.pythonOnBuildForHost.interpreter} get-repos.py
31 rm -rf vendor/*/.git
32 '';
33 };
34
35 build-system = [
36 setuptools
37 cython
38 ];
39 dependencies = [ tree-sitter ];
40 # Generate languages.so file (build won't fail without this, but tests will).
41 preBuild = ''
42 ${python.pythonOnBuildForHost.interpreter} build.py
43 '';
44 nativeCheckInputs = [ pytestCheckHook ];
45 # Without cd $out, tests fail to import the compiled cython extensions.
46 # Without copying the ./tests/ directory to $out, pytest won't detect the
47 # tests and run them. See also:
48 # https://github.com/NixOS/nixpkgs/issues/255262
49 preCheck = ''
50 cp -r tests $out/${python.sitePackages}/tree_sitter_languages
51 cd $out
52 '';
53
54 pythonImportsCheck = [ "tree_sitter_languages" ];
55
56 meta = with lib; {
57 description = "Binary Python wheels for all tree sitter languages";
58 homepage = "https://github.com/grantjenks/py-tree-sitter-languages";
59 license = licenses.asl20;
60 maintainers = with maintainers; [ doronbehar ];
61 # https://github.com/grantjenks/py-tree-sitter-languages/issues/67
62 broken = versionAtLeast tree-sitter.version "0.22";
63 };
64}