From 44fafa1694a11a5bc36ade7db7bc242f6b78a4c7 Mon Sep 17 00:00:00 2001 From: minhna1112 Date: Mon, 1 Jul 2024 11:09:56 +0700 Subject: [PATCH] Skip language build, use pre-built `get_language` --- src/codetext/utils/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/codetext/utils/utils.py b/src/codetext/utils/utils.py index 16c94f8..98d57e5 100644 --- a/src/codetext/utils/utils.py +++ b/src/codetext/utils/utils.py @@ -96,7 +96,7 @@ def parse_code(raw_code: str, language: str='Auto', tree_sitter_path: str=None) parser = Parser() try: from tree_sitter_languages import get_language, get_parser - parser = get_parser(get_language(language)) + language = get_language(language) except ImportError: # Work-around when pre-built binaries wheels for tree-sitter-languages are not available logger.warning(f"Troubled importing 'tree-sitter-languages', attemp to look for pre-built binaries in the workspace") @@ -104,9 +104,9 @@ def parse_code(raw_code: str, language: str='Auto', tree_sitter_path: str=None) if not os.path.exists(ts_lang_path): logger.warning(f"Not found `{language}.so` in `{load_path}/tree-sitter/`, attemp to build language") build_language(language, load_path) - language = Language(load_path + f"/tree-sitter/{language}.so", language) - parser.set_language(language) - + language = Language(load_path + f"/tree-sitter/{language}.so", language) + parser.set_language(language) + if isinstance(raw_code, str): raw_code = bytes(raw_code, 'utf8') elif isinstance(raw_code, bytes):