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.1";
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-LaU5dR7MULnmu/yji1dQGjxV5nGGqTnVvxSdnLciCXQ=";
32 };
33
34 # Upstream bumped dependencies aggressively, but we can still use older
35 # versions since the newer ones aren’t packaged in nixpkgs. We can't use
36 # pythonRelaxDepsHook here because it runs in postBuild, while the dependency
37 # check occurs during the build phase.
38 postPatch = ''
39 substituteInPlace pyproject.toml \
40 --replace-fail "typing-extensions>=4.15.0" "typing-extensions>=4.14.1"
41 '';
42
43 nativeCheckInputs = [
44 pytestCheckHook
45 ];
46
47 build-system = [
48 cython
49 setuptools
50 typing-extensions
51 ];
52
53 dependencies = [
54 tree-sitter
55 tree-sitter-c-sharp
56 tree-sitter-embedded-template
57 tree-sitter-yaml
58 ];
59
60 pythonRelaxDeps = [
61 "tree-sitter"
62 "tree-sitter-embedded-template"
63 "tree-sitter-yaml"
64 ];
65
66 pythonImportsCheck = [
67 "tree_sitter_language_pack"
68 "tree_sitter_language_pack.bindings"
69 ];
70
71 # make sure import the built version, not the source one
72 preCheck = ''
73 rm -r tree_sitter_language_pack
74 '';
75
76 passthru.updateScript = nix-update-script { };
77
78 meta = {
79 description = "Comprehensive collection of tree-sitter languages";
80 homepage = "https://github.com/Goldziher/tree-sitter-language-pack";
81 changelog = "https://github.com/Goldziher/tree-sitter-language-pack/releases/tag/v${version}";
82 license = lib.licenses.mit;
83 maintainers = with lib.maintainers; [ yzx9 ];
84 };
85}