Skip to content

Commit

Permalink
Fix Python TS bindings to <0.22.0.
Browse files Browse the repository at this point in the history
Building the tree-sitter-cpp library on our own will be removed in py-tree-sitter v0.22.0.
As long as the tree-sitter-cpp doesn;t have Python bindings
(see: tree-sitter/tree-sitter-cpp#250)
we have to stick to <0.22.0
  • Loading branch information
Rot127 committed Mar 25, 2024
1 parent 3862354 commit c4250ac
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
6 changes: 4 additions & 2 deletions suite/auto-sync/Updater/CppTranslator/Configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ def ts_compile_cpp(self) -> None:
ts_grammar_path = get_path("{VENDOR_DIR}").joinpath("tree-sitter-cpp")
if not Path.exists(ts_grammar_path):
fail_exit(f"Could not load the tree-sitter grammar at '{ts_grammar_path}'")
Language.build_library(str(self.ts_shared_object), [ts_grammar_path])
# build_library wll be deprecated in 0.22.0. But CPP tree-sitter doesn't have Python bindings.
# So we stick with it.
Language.build_library(str(self.ts_shared_object), [str(ts_grammar_path)])

def ts_set_cpp_language(self) -> None:
log.info(f"Load language '{self.ts_shared_object}'")
if not Path.exists(self.ts_shared_object):
fail_exit(f"Could not load the tree-sitter language shared object at '{self.ts_shared_object}'")
self.ts_cpp_lang = Language(self.ts_shared_object, "cpp")
self.ts_cpp_lang = Language(str(self.ts_shared_object), "cpp")

def init_parser(self) -> None:
log.debug("Init parser")
Expand Down
4 changes: 1 addition & 3 deletions suite/auto-sync/Updater/CppTranslator/CppTranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
from pathlib import Path

import termcolor
from tree_sitter import Language, Parser, Tree, Node
from tree_sitter import Language, Parser, Tree, Node, Query
import argparse
import logging as log
import sys

from tree_sitter.binding import Query

from CppTranslator.Configurator import Configurator
from Helper import convert_loglevel, print_prominent_warning, get_header, run_clang_format, get_path
from CppTranslator.Patches.GetRegFromClass import GetRegFromClass
Expand Down
3 changes: 1 addition & 2 deletions suite/auto-sync/Updater/CppTranslator/TemplateCollector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import re
from pathlib import Path

from tree_sitter import Language, Parser
from tree_sitter import Language, Parser, Query, Node
import logging as log

from tree_sitter.binding import Query, Node
from CppTranslator.Patches.HelperMethods import get_text


Expand Down
2 changes: 1 addition & 1 deletion suite/auto-sync/Updater/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
termcolor>=2.3.0
tree_sitter>=0.20.2
tree_sitter<0.22.0

0 comments on commit c4250ac

Please sign in to comment.