1{
2 lib,
3 buildPythonPackage,
4 fetchPypi,
5 pytestCheckHook,
6 nix-update-script,
7
8 # build-system
9 cython,
10 setuptools,
11 typing-extensions,
12
13 # dependencies
14 tree-sitter,
15 tree-sitter-c-sharp,
16 tree-sitter-embedded-template,
17 tree-sitter-yaml,
18}:
19
20buildPythonPackage rec {
21 pname = "tree-sitter-language-pack";
22 version = "0.9.0";
23 pyproject = true;
24
25 # Using the GitHub sources necessitates fetching the treesitter grammar parsers by using a vendored script.
26 # The pypi archive has the benefit of already vendoring those dependencies which makes packaging easier on our side
27 # See: https://github.com/Goldziher/tree-sitter-language-pack/blob/main/scripts/clone_vendors.py
28 src = fetchPypi {
29 pname = "tree_sitter_language_pack";
30 inherit version;
31 hash = "sha256-kA6zvYLBvPXPIO2FKxtv3H6uieQKhg+l4iGnlmh8NZo=";
32 };
33
34 # Upstream bumped the setuptools and typing-extensions dependencies, but we can still use older versions
35 # since the newer ones aren’t packaged in nixpkgs. We can't use pythonRelaxDepsHook here because it runs
36 # in postBuild, while the dependency check occurs during the build phase.
37 postPatch = ''
38 substituteInPlace pyproject.toml \
39 --replace-fail "setuptools>=80.9.0" "setuptools>=78.1.0" \
40 --replace-fail "typing-extensions>=4.14.0" "typing-extensions>=4.13.2"
41 '';
42
43 build-system = [
44 cython
45 setuptools
46 typing-extensions
47 ];
48
49 dependencies = [
50 tree-sitter
51 tree-sitter-c-sharp
52 tree-sitter-embedded-template
53 tree-sitter-yaml
54 ];
55
56 nativeCheckInputs = [
57 pytestCheckHook
58 ];
59
60 pythonImportsCheck = [
61 "tree_sitter_language_pack"
62 "tree_sitter_language_pack.bindings"
63 ];
64
65 preCheck = ''
66 # make sure import the built version, not the source one
67 rm -r tree_sitter_language_pack
68 '';
69
70 passthru.updateScript = nix-update-script { };
71
72 meta = {
73 description = "Comprehensive collection of tree-sitter languages";
74 homepage = "https://github.com/Goldziher/tree-sitter-language-pack";
75 changelog = "https://github.com/Goldziher/tree-sitter-language-pack/releases/tag/v${version}";
76 license = lib.licenses.mit;
77 maintainers = with lib.maintainers; [ yzx9 ];
78 };
79}