Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 buildPythonPackage, 4 fetchPypi, 5 python, 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.7.3"; 23 pyproject = true; 24 25 # Using the GitHub sources necessitates fetching the treesitter grammar parsers by using a vendored script: 26 # https://github.com/Goldziher/tree-sitter-language-pack/blob/main/scripts/clone_vendors.py 27 # The pypi archive has the benefit of already vendoring those dependencies which makes packaging easier on our side 28 src = fetchPypi { 29 pname = "tree_sitter_language_pack"; 30 inherit version; 31 hash = "sha256-SROctgfYE1LTOtGOV1IPwQV6AJlVyczO1WYHzBjmo/0="; 32 }; 33 34 build-system = [ 35 cython 36 setuptools 37 typing-extensions 38 ]; 39 40 dependencies = [ 41 tree-sitter 42 tree-sitter-c-sharp 43 tree-sitter-embedded-template 44 tree-sitter-yaml 45 ]; 46 47 prePatch = '' 48 # Remove the packaged bindings, which only work on Linux and prevent the build from succeeding 49 # https://github.com/Goldziher/tree-sitter-language-pack/issues/46 50 rm -rf tree_sitter_language_pack/bindings/*.so 51 ''; 52 53 pythonImportsCheck = [ 54 "tree_sitter_language_pack" 55 "tree_sitter_language_pack.bindings" 56 ]; 57 58 # No tests in the pypi archive, we add a test to check that all bindings can be imported 59 checkPhase = '' 60 runHook preCheck 61 62 cat <<EOF > test-import-bindings.py 63 import sys 64 import os 65 if (cwd := os.getcwd()) in sys.path: 66 # remove current working directory from sys.path, use PYTHONPATH instead 67 sys.path.remove(cwd) 68 69 from typing import get_args 70 from tree_sitter_language_pack import SupportedLanguage, get_binding 71 72 for lang in get_args(SupportedLanguage): 73 get_binding(lang) 74 EOF 75 76 ${python.interpreter} test-import-bindings.py 77 78 runHook postCheck 79 ''; 80 81 passthru.updateScript = nix-update-script { }; 82 83 meta = { 84 description = "Comprehensive collection of tree-sitter languages"; 85 homepage = "https://github.com/Goldziher/tree-sitter-language-pack"; 86 changelog = "https://github.com/Goldziher/tree-sitter-language-pack/releases/tag/v${version}"; 87 license = lib.licenses.mit; 88 maintainers = with lib.maintainers; [ yzx9 ]; 89 }; 90}